Java Code Examples for java.nio.ByteOrder#equals()

The following examples show how to use java.nio.ByteOrder#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrestoSystemRequirements.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void verifyByteOrder()
{
    ByteOrder order = ByteOrder.nativeOrder();
    if (!order.equals(ByteOrder.LITTLE_ENDIAN)) {
        failRequirement("Presto requires a little endian platform (found %s)", order);
    }
}
 
Example 2
Source File: BitBuffer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the order of the buffer.
 *
 * @param order
 *            The order of the buffer.
 */
public void setByteOrder(ByteOrder order) {
    if (!order.equals(fByteOrder)) {
        fByteOrder = order;
        fBuffer.order(order);
    }
}
 
Example 3
Source File: NonBlockingBitInputStream.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new bit input stream based on an existing Java InputStream.
 *
 * @param aIS
 *        the input stream this class should read the bits from. May not be
 *        <code>null</code>.
 * @param aByteOrder
 *        The non-<code>null</code> byte order to use.
 */
public NonBlockingBitInputStream (@Nonnull final InputStream aIS, @Nonnull final ByteOrder aByteOrder)
{
  ValueEnforcer.notNull (aIS, "InputStream");
  ValueEnforcer.notNull (aByteOrder, "ByteOrder");

  m_aIS = StreamHelper.getBuffered (aIS);
  m_bHighOrderBitFirst = aByteOrder.equals (ByteOrder.LITTLE_ENDIAN);
  m_nNextBitIndex = CGlobal.BITS_PER_BYTE;
}
 
Example 4
Source File: NonBlockingBitOutputStream.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new bit output stream based on an existing Java OutputStream.
 *
 * @param aOS
 *        the output stream this class should use. May not be
 *        <code>null</code>.
 * @param aByteOrder
 *        The non-<code>null</code> byte order to use.
 */
public NonBlockingBitOutputStream (@Nonnull final OutputStream aOS, @Nonnull final ByteOrder aByteOrder)
{
  ValueEnforcer.notNull (aOS, "OutputStream");
  ValueEnforcer.notNull (aByteOrder, "ByteOrder");

  m_aOS = aOS;
  m_bHighOrderBitFirst = aByteOrder.equals (ByteOrder.LITTLE_ENDIAN);
  m_nBufferedBitCount = 0;
}
 
Example 5
Source File: ChannelBuffers.java    From simple-netty-source with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new composite buffer which wraps the slices of the specified
 * NIO buffers without copying them.  A modification on the content of the
 * specified buffers will be visible to the returned buffer.
 * If gathering is {@code true} then gathering writes will be used when ever
 * possible.
 *
 * @throws IllegalArgumentException
 *         if the specified buffers' endianness are different from each
 *         other
 */
public static ChannelBuffer wrappedBuffer(boolean gathering, ByteBuffer... buffers) {
    switch (buffers.length) {
    case 0:
        break;
    case 1:
        if (buffers[0].hasRemaining()) {
            return wrappedBuffer(buffers[0]);
        }
        break;
    default:
        ByteOrder order = null;
        final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(buffers.length);
        for (ByteBuffer b: buffers) {
            if (b == null) {
                break;
            }
            if (b.hasRemaining()) {
                if (order != null) {
                    if (!order.equals(b.order())) {
                        throw new IllegalArgumentException(
                                "inconsistent byte order");
                    }
                } else {
                    order = b.order();
                }
                components.add(wrappedBuffer(b));
            }
        }
        return compositeBuffer(order, components, gathering);
    }

    return EMPTY_BUFFER;
}
 
Example 6
Source File: ChannelBuffers.java    From android-netty with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new composite buffer which wraps the slices of the specified
 * NIO buffers without copying them.  A modification on the content of the
 * specified buffers will be visible to the returned buffer.
 * If gathering is {@code true} then gathering writes will be used when ever
 * possible.
 *
 * @throws IllegalArgumentException
 *         if the specified buffers' endianness are different from each
 *         other
 */
public static ChannelBuffer wrappedBuffer(boolean gathering, ByteBuffer... buffers) {
    switch (buffers.length) {
    case 0:
        break;
    case 1:
        if (buffers[0].hasRemaining()) {
            return wrappedBuffer(buffers[0]);
        }
        break;
    default:
        ByteOrder order = null;
        final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(buffers.length);
        for (ByteBuffer b: buffers) {
            if (b == null) {
                break;
            }
            if (b.hasRemaining()) {
                if (order != null) {
                    if (!order.equals(b.order())) {
                        throw new IllegalArgumentException(
                                "inconsistent byte order");
                    }
                } else {
                    order = b.order();
                }
                components.add(wrappedBuffer(b));
            }
        }
        return compositeBuffer(order, components, gathering);
    }

    return EMPTY_BUFFER;
}
 
Example 7
Source File: RandomAccessFile.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void order(ByteOrder bo) {
  if (bo == null)
    return;
  this.bigEndian = bo.equals(ByteOrder.BIG_ENDIAN);
}
 
Example 8
Source File: IntegerDeclaration.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean isBigEndian(@Nullable ByteOrder byteOrder) {
    return (byteOrder != null) && byteOrder.equals(ByteOrder.BIG_ENDIAN);
}
 
Example 9
Source File: ChannelBuffers.java    From simple-netty-source with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new composite buffer which wraps the readable bytes of the
 * specified buffers without copying them.  A modification on the content
 * of the specified buffers will be visible to the returned buffer.
 * If gathering is {@code true} then gathering writes will be used when ever
 * possible.
 *
 * @throws IllegalArgumentException
 *         if the specified buffers' endianness are different from each
 *         other
 */
public static ChannelBuffer wrappedBuffer(boolean gathering, ChannelBuffer... buffers) {
    switch (buffers.length) {
    case 0:
        break;
    case 1:
        if (buffers[0].readable()) {
            return wrappedBuffer(buffers[0]);
        }
        break;
    default:
        ByteOrder order = null;
        final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(buffers.length);
        for (ChannelBuffer c: buffers) {
            if (c == null) {
                break;
            }
            if (c.readable()) {
                if (order != null) {
                    if (!order.equals(c.order())) {
                        throw new IllegalArgumentException(
                                "inconsistent byte order");
                    }
                } else {
                    order = c.order();
                }
                if (c instanceof CompositeChannelBuffer) {
                    // Expand nested composition.
                    components.addAll(
                            ((CompositeChannelBuffer) c).decompose(
                                    c.readerIndex(), c.readableBytes()));
                } else {
                    // An ordinary buffer (non-composite)
                    components.add(c.slice());
                }
            }
        }
        return compositeBuffer(order, components, gathering);
    }
    return EMPTY_BUFFER;
}
 
Example 10
Source File: DirectMemory.java    From util with Apache License 2.0 4 votes vote down vote up
DirectMemory(long address, long length, ByteOrder order) {
    this.address = address;
    this.length = length;
    this.order = order;
    directDataAccess = order.equals(ByteOrder.nativeOrder()) ? NativeEndianDirectDataAccess.getInstance() : ReverseEndianDirectDataAccess.getInstance();
}
 
Example 11
Source File: ChannelBuffers.java    From android-netty with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new composite buffer which wraps the readable bytes of the
 * specified buffers without copying them.  A modification on the content
 * of the specified buffers will be visible to the returned buffer.
 * If gathering is {@code true} then gathering writes will be used when ever
 * possible.
 *
 * @throws IllegalArgumentException
 *         if the specified buffers' endianness are different from each
 *         other
 */
public static ChannelBuffer wrappedBuffer(boolean gathering, ChannelBuffer... buffers) {
    switch (buffers.length) {
    case 0:
        break;
    case 1:
        if (buffers[0].readable()) {
            return wrappedBuffer(buffers[0]);
        }
        break;
    default:
        ByteOrder order = null;
        final List<ChannelBuffer> components = new ArrayList<ChannelBuffer>(buffers.length);
        for (ChannelBuffer c: buffers) {
            if (c == null) {
                break;
            }
            if (c.readable()) {
                if (order != null) {
                    if (!order.equals(c.order())) {
                        throw new IllegalArgumentException(
                                "inconsistent byte order");
                    }
                } else {
                    order = c.order();
                }
                if (c instanceof CompositeChannelBuffer) {
                    // Expand nested composition.
                    components.addAll(
                            ((CompositeChannelBuffer) c).decompose(
                                    c.readerIndex(), c.readableBytes()));
                } else {
                    // An ordinary buffer (non-composite)
                    components.add(c.slice());
                }
            }
        }
        return compositeBuffer(order, components, gathering);
    }
    return EMPTY_BUFFER;
}
 
Example 12
Source File: ByteInputStream.java    From qJava with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the byte order for reading the wrapeed buffer.
 * 
 * @param endianess
 *            byte order
 */
public void setOrder( final ByteOrder endianess ) {
    this.reader = endianess.equals(ByteOrder.LITTLE_ENDIAN) ? readerLittleEndian : readerBigEndian;
}