View Javadoc

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
    10   *    http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   *  Unless required by applicable law or agreed to in writing,
    13   *  software distributed under the License is distributed on an
    14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   *  KIND, either express or implied.  See the License for the
    16   *  specific language governing permissions and limitations
    17   *  under the License.
    18   *
    19   */
    20  package org.apache.mina.codec.delimited.ints;
    21
    22  import java.nio.ByteBuffer;
    23  import java.nio.ByteOrder;
    24  import java.util.HashMap;
    25  import java.util.LinkedList;
    26  import java.util.List;
    27  import java.util.Map;
    28
    29  import org.apache.mina.codec.delimited.ByteBufferEncoder;
    30  import org.apache.mina.codec.delimited.IoBufferDecoder;
    31
    32  /**
    33   * A {@link Int32Decoder} and {@link Int32Encoder} test in a big endian setup.
    34   *
    35   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
    36   */
    37  public class RawInt32BigEndianEncodingTest extends IntEncodingTest {
    38
    39      @Override
    40      public IoBufferDecoder<Integer> newDecoderInstance() {
    41          return new RawInt32(ByteOrder.BIG_ENDIAN).getDecoder();
    42      }
    43
    44      @Override
    45      public ByteBufferEncoder<Integer> newEncoderInstance() {
    46          return new RawInt32(ByteOrder.BIG_ENDIAN).getEncoder();
    47      }
    48
    49      @Override
    50      public Map<Integer, ByteBuffer> getEncodingSamples() {
    51          Map<Integer, ByteBuffer> map = new HashMap<Integer, ByteBuffer>();
    52
    53          map.put(0, ByteBuffer.wrap(new byte[] { 0, 0, 0, 0 }));
    54          map.put(1 << 24 | 2 << 16 | 3 << 8 | 4, ByteBuffer.wrap(new byte[] { 1, 2, 3, 4 }));
    55          return map;
    56      }
    57
    58      @Override
    59      public Iterable<ByteBuffer> getIllegalBuffers() {
    60          List<ByteBuffer> list = new LinkedList<ByteBuffer>();
    61          return list;
    62      }
    63  }