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:org.apache.hadoop.hbase.filter.DirectoryRowFilter.java
/** * Serialize the filter//ww w . j a v a2 s . c om */ @Override public byte[] toByteArray() throws IOException { ByteBuffer bb = ByteBuffer.wrap(new byte[4 * 8]).order(ByteOrder.BIG_ENDIAN); bb.putLong(instanceModulus); bb.putLong(instanceRemainder); bb.putLong(threadModulus); bb.putLong(threadRemainder); return bb.array(); }
From source file:edu.harvard.iq.dvn.unf.Base64Encoding.java
/** * Helper function to change the endianess of the byte array * * @param digest byte array/* w ww . ja v a2 s .c o m*/ * @param local ByteOrder * @return byte array with endianness according to getBorder() */ public static byte[] changeByteOrder(byte[] digest, ByteOrder local) { byte[] revdigest = new byte[digest.length]; if ((local.equals(ByteOrder.LITTLE_ENDIAN) && getBorder().equals(ByteOrder.BIG_ENDIAN)) || (local.equals(ByteOrder.BIG_ENDIAN) && getBorder().equals(ByteOrder.LITTLE_ENDIAN))) { int ln = digest.length; for (int n = 0; n < ln; ++n) { revdigest[n] = digest[ln - 1 - n]; } } else { revdigest = digest; } return revdigest; }
From source file:com.googlecode.mp4parser.boxes.microsoft.XtraBox.java
@Override public void _parseDetails(ByteBuffer content) { int boxSize = content.remaining(); data = content.slice(); //Keep this in case we fail to parse successfulParse = false;//from ww w.j av a2s . c o m try { tags.clear(); while (content.remaining() > 0) { XtraTag tag = new XtraTag(); tag.parse(content); tags.addElement(tag); } int calcSize = detailSize(); if (boxSize != calcSize) { throw new RuntimeException("Improperly handled Xtra tag: Calculated sizes don't match ( " + boxSize + "/" + calcSize + ")"); } successfulParse = true; } catch (Exception e) { successfulParse = false; System.err.println("Malformed Xtra Tag detected: " + e.toString()); e.printStackTrace(); content.position(content.position() + content.remaining()); } finally { content.order(ByteOrder.BIG_ENDIAN); //Just in case we bailed out mid-parse we don't want to leave the byte order in MS land } }
From source file:com.slytechs.capture.FileFactory.java
public <T extends FileCapture<? extends FilePacket>> T newFile(final Class<T> c, final File file) throws IOException, FileFormatException { if (c == PcapFile.class) { final FileCapture pcap = PcapFileCapture.createFile(file, FileMode.ReadWrite, ByteOrder.BIG_ENDIAN, null);/*from ww w . j ava 2 s . c o m*/ return c.cast(pcap); } if (c == SnoopFile.class) { final FileCapture snoop = SnoopFileCapture.createFile(file, FileMode.ReadWrite, null); return c.cast(snoop); } else { throw new FileFormatException("Unknown file format " + c.getName()); } }
From source file:com.amazonaws.services.kinesis.producer.Daemon.java
/** * Starts up the child process, connects to it, and beings sending and * receiving messages.// w ww.j ava 2 s . co m * * @param pathToExecutable * Path to the binary that we will use to start up the child. * @param handler * Message handler that handles messages received from the child. * @param workingDir * Working directory. The KPL creates FIFO files; it will do so * in this directory. * @param config * KPL configuration. */ public Daemon(String pathToExecutable, MessageHandler handler, String workingDir, KinesisProducerConfiguration config, Map<String, String> environmentVariables) { this.pathToExecutable = pathToExecutable; this.handler = handler; this.workingDir = workingDir; this.config = config; this.environmentVariables = environmentVariables; lenBuf.order(ByteOrder.BIG_ENDIAN); rcvBuf.order(ByteOrder.BIG_ENDIAN); executor.submit(new Runnable() { @Override public void run() { try { createPipes(); startChildProcess(); } catch (Exception e) { fatalError("Error running child process", e); } } }); }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.java
static ByteBuffer makeCompositeBuffer(byte[] colName, long ts) { assert colName.length <= 1 << 16 : "Cannot use column names larger than 64KiB, was " + colName.length; ByteBuffer buffer = ByteBuffer.allocate(6 /* misc */ + 8 /* timestamp */ + colName.length) .order(ByteOrder.BIG_ENDIAN); buffer.put((byte) ((colName.length >> 8) & 0xFF)); buffer.put((byte) (colName.length & 0xFF)); buffer.put(colName);/*www . ja v a 2s.c om*/ buffer.put((byte) 0); buffer.put((byte) 0); buffer.put((byte) (8 & 0xFF)); buffer.putLong(~ts); buffer.put((byte) 0); buffer.flip(); return buffer; }
From source file:org.xenei.compressedgraph.SerializableNode.java
private ByteBuffer getByteBuffer() { if (buffer == null) { buffer = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN); } return buffer; }
From source file:org.mcisb.util.math.MathUtils.java
/** * /* w w w . j a v a 2 s . co m*/ * @param encoded * @param bigEndian * @param doublePrecision * @return double[] */ public static double[] decode(final byte[] encoded, final boolean bigEndian, final boolean doublePrecision) { final byte[] bytes = Base64.decode(encoded); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer = byteBuffer.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); final int limit = byteBuffer.limit(); double[] decoded = new double[((doublePrecision) ? limit / DOUBLE_LENGTH : limit / FLOAT_LENGTH)]; int i = 0; while (byteBuffer.hasRemaining()) { if (doublePrecision) { decoded[i++] = byteBuffer.getDouble(); } else { decoded[i++] = byteBuffer.getFloat(); } } return decoded; }
From source file:org.projectnyx.network.mcpe.raknet.RakNetInterface.java
private void handleDataPacket(RawDataPacket packet) { ByteBuffer buffer = ByteBuffer.wrap(packet.buffer).order(ByteOrder.BIG_ENDIAN); byte pid = buffer.get(); if (pid == DATA_PING) { long pingId = buffer.getLong(); Pong pong = new Pong(); pong.pingId = pingId;/* w w w . ja v a2 s . com*/ RawDataPacket pk = new RawDataPacket(); pk.reliability = 0; pk.buffer = pong.write().array(); queueDataPacket(pk); return; } if (pid == DATA_PONG) { long pingId = buffer.getLong(); Ping ping = pingMap.remove(pingId); if (ping == null) { Nyx.getLog().error(String.format("Client from %s sent PONG with unknown ping ID %d", client.getAddress(), pingId)); return; } client.getPingStats().addDatum(ping.sendTimeNano, true); return; } if (pid == DATA_CLIENT_DISCONNECT) { client.close(Client.CloseReason.CLIENT_DISCONNECT); } if (client.getLoginStep() == LOGIN_STEP_WAIT_CONNECT) { if (pid != DATA_CLIENT_CONENCT) { client.unexpectedPacket(packet); return; } ClientConnect request = new ClientConnect(buffer); ServerHandshake response = new ServerHandshake(); response.address = client.getSession().getAddress(); response.ping = request.pingTime; response.pong = request.pingTime + 1000; RawDataPacket pk = new RawDataPacket(); pk.reliability = 0; pk.buffer = response.write().array(); queueDataPacket(pk); flushDataPacketQueue(); client.setLoginStep(LOGIN_STEP_WAIT_HANDSHAKE); } else if (client.getLoginStep() == LOGIN_STEP_WAIT_HANDSHAKE) { if (pid != DATA_CLIENT_HANDSHAKE) { client.unexpectedPacket(packet); return; } ClientHandshake handshake = new ClientHandshake(buffer); // TODO log referrer? // TODO check port? client.setLoginStep(LOGIN_STEP_IN_GAME); Nyx.getLog().debug(String.format("Client %s is now logging in!", client.getAddress())); } else if (client.getLoginStep() != LOGIN_STEP_IN_GAME) { client.unexpectedPacket(packet); } else { if (pid != RakNetConsts.DATA_MCPE) { client.unexpectedPacket(packet); return; } client.handleDataPacket(buffer); } }
From source file:org.esa.s2tbx.dataio.spot.dimap.SpotViewMetadataTest.java
@Test public void testGetGeolayerJavaByteOrder() throws Exception { assertEquals(ByteOrder.BIG_ENDIAN, metadata.getGeolayerJavaByteOrder()); }