List of usage examples for java.nio ByteOrder BIG_ENDIAN
ByteOrder BIG_ENDIAN
To view the source code for java.nio ByteOrder BIG_ENDIAN.
Click Source Link
From source file:io.druid.segment.data.CompressedColumnarIntsSerializerTest.java
@Parameterized.Parameters(name = "{index}: compression={0}, byteOrder={1}") public static Iterable<Object[]> compressionStrategiesAndByteOrders() { Set<List<Object>> combinations = Sets.cartesianProduct(Sets.newHashSet(CompressionStrategy.noNoneValues()), Sets.newHashSet(ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN)); return Iterables.transform(combinations, new Function<List, Object[]>() { @Override//from w w w. ja v a2 s. co m public Object[] apply(List input) { return new Object[] { input.get(0), input.get(1) }; } }); }
From source file:byps.test.TestSerializePrimitiveTypes.java
/** * BBufferBin/BBufferJson re-allocate an internal ByteBuffer, * if the buffer supplied in the constructor is too small. * The bytes written so far have to be copied into the new Buffer. * @throws BException // w w w . j a v a 2 s . c om */ @Test public void testBufferRealloc() throws BException { log.info("testBufferRealloc("); internalTestBufferRealloc(ByteOrder.BIG_ENDIAN); internalTestBufferRealloc(ByteOrder.LITTLE_ENDIAN); log.info(")testBufferRealloc"); }
From source file:tor.Cell.java
public byte[] getBytes(int protocolVersion) { byte cell[];/*from w w w .j a va2 s . co m*/ if (cmdId == 7 || cmdId >= 128) cell = new byte[(protocolVersion < 4 ? 3 : 5) + 2 + payload.length]; else cell = new byte[protocolVersion < 4 ? 512 : 514]; ByteBuffer buf = ByteBuffer.wrap(cell); buf.order(ByteOrder.BIG_ENDIAN); if (protocolVersion < 4) buf.putShort((short) circId); else buf.putInt((int) circId); buf.put((byte) cmdId); if (cmdId == 7 || cmdId >= 128) buf.putShort((short) payload.length); if (payload != null) buf.put(payload); //System.out.println("Sending:" + byteArrayToHex(cell)); return cell; }
From source file:org.apache.hadoop.mapred.nativetask.NativeBatchProcessor.java
public NativeBatchProcessor(Class<IK> iKClass, Class<IV> iVClass, Class<OK> oKClass, Class<OV> oVClass, String nativeHandlerName, int inputBufferCapacity, int outputBufferCapacity) throws IOException { if (inputBufferCapacity > 0) { this.inputBuffer = ByteBuffer.allocateDirect(inputBufferCapacity); this.inputBuffer.order(ByteOrder.BIG_ENDIAN); }/* w w w .ja v a2 s. c o m*/ if (outputBufferCapacity > 0) { this.outputBuffer = ByteBuffer.allocateDirect(outputBufferCapacity); this.outputBuffer.order(ByteOrder.BIG_ENDIAN); } this.nativeHandlerName = nativeHandlerName; this.nativeReader = new NativeInputStream(outputBuffer); this.nativeWriter = new NativeOutputStream(inputBuffer) { @Override public void flush() throws IOException { flushInputAndProcess(); } @Override public void close() throws IOException { finishInput(); } }; if (null != iKClass && null != iVClass) { this.serializer = new KVSerializer<IK, IV>(iKClass, iVClass); } if (null != oKClass && null != oVClass) { this.deserializer = new KVSerializer<OK, OV>(oKClass, oVClass); } }
From source file:nl.salp.warcraft4j.util.DataTypeUtil.java
/** * Create a fixed-size 32-bit (4 byte) byte[] from an int value using a big endian byte order. * * @param value The value./*from w w w . j av a 2 s.c o m*/ * * @return The byte[]. */ public static byte[] toByteArray(int value) { return toByteArray(value, ByteOrder.BIG_ENDIAN); }
From source file:com.netflix.suro.jackson.DefaultObjectMapper.java
@Inject public DefaultObjectMapper(final Injector injector, Set<TypeHolder> crossInjectable) { SimpleModule serializerModule = new SimpleModule("SuroServer default serializers"); serializerModule.addSerializer(ByteOrder.class, ToStringSerializer.instance); serializerModule.addDeserializer(ByteOrder.class, new JsonDeserializer<ByteOrder>() { @Override/*from w w w . ja v a 2 s . c o m*/ public ByteOrder deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (ByteOrder.BIG_ENDIAN.toString().equals(jp.getText())) { return ByteOrder.BIG_ENDIAN; } return ByteOrder.LITTLE_ENDIAN; } }); registerModule(serializerModule); registerModule(new GuavaModule()); if (injector != null) { setInjectableValues(new InjectableValues() { @Override public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) { LOG.info("Looking for " + valueId); try { return injector.getInstance( Key.get(forProperty.getType().getRawClass(), Names.named((String) valueId))); } catch (Exception e) { try { return injector.getInstance(forProperty.getType().getRawClass()); } catch (Exception ex) { LOG.info("No implementation found, returning null"); } return null; } } }); } configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); configure(MapperFeature.AUTO_DETECT_GETTERS, false); configure(MapperFeature.AUTO_DETECT_CREATORS, false); configure(MapperFeature.AUTO_DETECT_FIELDS, false); configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); configure(MapperFeature.AUTO_DETECT_SETTERS, false); configure(SerializationFeature.INDENT_OUTPUT, false); if (crossInjectable != null) { for (TypeHolder entry : crossInjectable) { LOG.info("Registering subtype : " + entry.getName() + " -> " + entry.getRawType().getCanonicalName()); registerSubtypes(new NamedType(entry.getRawType(), entry.getName())); } } }
From source file:nl.salp.warcraft4j.util.Checksum.java
/** * Trim the checksum to a length, resizing it (cutting off the right bytes) if the checksum is bigger then the provided length. * * @param length The length in bytes.// w w w. j a v a 2 s . c o m * * @return A new checksum instance with a maximum of the provided length. * * @throws IllegalArgumentException When the length is {@code 0} or negative. */ public Checksum trim(int length) throws IllegalArgumentException { return trim(length, ByteOrder.BIG_ENDIAN); }
From source file:eu.xworlds.util.raknet.protocol.BaseMessage.java
/** * writes an unsigned int to byte buf//from w ww. jav a 2s . c o m * * @param target target byte buffer. * @param value the unsigned short value. */ protected void writeUnsignedInt(ByteBuf target, long value) { if (value < 0 || value > 0xffffffl) { throw new IllegalArgumentException(value + " exceeds allowed size"); //$NON-NLS-1$ } if (target.order() == ByteOrder.BIG_ENDIAN) { target.writeByte((int) value >> 32); target.writeByte((int) value >> 16); target.writeByte((int) value >> 8); target.writeByte((int) value); } else { target.writeByte((int) value); target.writeByte((int) value >> 8); target.writeByte((int) value >> 16); target.writeByte((int) value >> 32); } }
From source file:nl.salp.warcraft4j.util.DataTypeUtil.java
/** * Create a fixed-size 32-bit (4 byte) byte[] from an int value using a byte order. * * @param value The value./* w w w.j av a 2 s. c o m*/ * @param byteOrder The byte order, using {@code ByteOrder#BIG_ENDIAN} when the byte order is {@code null}. * * @return The byte[]. */ public static byte[] toByteArray(int value, ByteOrder byteOrder) { byte[] intArray = new byte[Integer.BYTES]; ByteBuffer.wrap(intArray).order(Optional.ofNullable(byteOrder).orElse(ByteOrder.BIG_ENDIAN)).putInt(value); return intArray; }
From source file:com.slytechs.file.snoop.SnoopFileCapture.java
/** * Creates a new file by creating an empty file, then writting a block header * into it and then closes the created file. The file has to be reopened as a * normal file if you need access to its contents. * /*from ww w . j ava 2 s .c om*/ * @param file * file to create * @param mode * TODO * @param filter * TODO * @param order * byte ordering for all the headers within the file * @throws FileNotFoundException * unable to find parent directory inorder to create a new file * @throws IOException * any IO errors * @throws FileFormatException */ public static SnoopFile createFile(final File file, final FileMode mode, Filter<ProtocolFilterTarget> filter) throws FileNotFoundException, IOException, FileFormatException { if (logger.isDebugEnabled()) { logger.debug(file.getName() + ", mode=" + mode + (filter == null ? "" : filter)); } // Create empty file? if (file.createNewFile() == false) { throw new FileNotFoundException("Unable to create new file [" + file.getName() + "]"); } SnoopFile capture = new SnoopFileCapture(FileMode.ReadWrite); /* * Open up in READONLY MODE since file is empty anyway, nothing to override, * we will append memory cache based segments and flush them out. */ final FileEditor editor = new FileEditorImpl(file, FileMode.ReadWrite, headerReader, ByteOrder.BIG_ENDIAN, filter, (RawIteratorBuilder) capture); SnoopBlockRecordImpl.createBlock(capture, editor); editor.close(); // Flush and close capture = new SnoopFileCapture(file, mode, null); return capture; }