List of usage examples for java.nio ByteBuffer order
Endianness order
To view the source code for java.nio ByteBuffer order.
Click Source Link
From source file:com.kentdisplays.synccardboarddemo.Page.java
/** * Sets up the drawing object data for use in an OpenGL ES context. * * @param is InputStream to the page to load the path data from. *///from ww w.ja v a2 s. c o m public Page(InputStream is, int glProgram, int direction) { this.mModel = new float[16]; this.mGlProgram = glProgram; // Calculate the coordinates from the given path. ArrayList<Path> paths = pathsFromSamplePageInputStream(is); float finalCoords[] = {}; float finalNormals[] = {}; float finalColors[] = {}; mNumberOfPaths = paths.size(); for (int i = 0; i < mNumberOfPaths; i++) { Path path = paths.get(i); float x1 = (path.x1 / 13942 * 2) - 1; float y1 = (path.y1 / 20280 * 2) - 1; float x2 = (path.x2 / 13942 * 2) - 1; float y2 = (path.y2 / 20280 * 2) - 1; float width = path.width / 3000; width = width < 0.013f ? 0.013f : width; // Width should be at least 0.013 float distance = (float) Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); float angle = (float) Math.PI / 2 - (float) Math.asin((x2 - x1) / distance); float xdiff = (width / 2) * (float) Math.sin(angle); float ydiff = (width / 2) * (float) Math.cos(angle); float coords[] = { x1 - xdiff, y1 - ydiff, 1.0f, // top left x2 - xdiff, y2 - ydiff, 1.0f, // bottom left x1 + xdiff, y1 + ydiff, 1.0f, // top right x2 - xdiff, y2 - ydiff, 1.0f, // bottom left x2 + xdiff, y2 + ydiff, 1.0f, // bottom right x1 + xdiff, y1 + ydiff, 1.0f, // top right }; float normals[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, }; float colors[] = { 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, }; finalCoords = Floats.concat(finalCoords, coords); finalNormals = Floats.concat(finalNormals, normals); finalColors = Floats.concat(finalColors, colors); } ByteBuffer bbVertices = ByteBuffer.allocateDirect(finalCoords.length * 4); bbVertices.order(ByteOrder.nativeOrder()); mPageVertices = bbVertices.asFloatBuffer(); mPageVertices.put(finalCoords); mPageVertices.position(0); ByteBuffer bbNormals = ByteBuffer.allocateDirect(finalNormals.length * 4); bbNormals.order(ByteOrder.nativeOrder()); mPageNormals = bbNormals.asFloatBuffer(); mPageNormals.put(finalNormals); mPageNormals.position(0); ByteBuffer bbColors = ByteBuffer.allocateDirect(finalColors.length * 4); bbColors.order(ByteOrder.nativeOrder()); mPageColors = bbColors.asFloatBuffer(); mPageColors.put(finalColors); mPageColors.position(0); // Correctly place the page in the world. Matrix.setIdentityM(mModel, 0); switch (direction) { case 0: Matrix.translateM(mModel, 0, 0, 0, -mDistance); //Front. break; case 1: Matrix.translateM(mModel, 0, -mDistance, 0, 0); // Left. Matrix.rotateM(mModel, 0, 90, 0, 1f, 0); break; case 2: Matrix.translateM(mModel, 0, 0, 0, mDistance); // Behind. Matrix.rotateM(mModel, 0, 180, 0, 1f, 0); break; case 3: Matrix.translateM(mModel, 0, mDistance, 0, 0); // Right. Matrix.rotateM(mModel, 0, 270, 0, 1f, 0); break; } }
From source file:org.apache.nifi.processors.evtx.parser.BinaryReader.java
/** * Reads 8 bytes in litte endian order and returns the UnsignedLong value * * @return the value// w w w. j a v a 2 s .co m */ public UnsignedLong readQWord() { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, position, 8); position += 8; return UnsignedLong.fromLongBits(byteBuffer.order(ByteOrder.LITTLE_ENDIAN).getLong()); }
From source file:org.apache.nifi.processors.evtx.parser.BinaryReader.java
/** * Reads 4 bytes in little endian order and returns the UnsignedInteger value * * @return the value//from w w w . j a va 2 s. c o m */ public UnsignedInteger readDWord() { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, position, 4); position += 4; return UnsignedInteger.fromIntBits(byteBuffer.order(ByteOrder.LITTLE_ENDIAN).getInt()); }
From source file:org.apache.nifi.processors.evtx.parser.BinaryReader.java
/** * Reads 4 bytes in big endian order and returns the UnsignedInteger value * * @return the value/*w w w .j a va 2s.c om*/ */ public UnsignedInteger readDWordBE() { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, position, 4); position += 4; return UnsignedInteger.fromIntBits(byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt()); }
From source file:adapter.davis.DavisSensor.java
/** * Expecting ACK message./*from w w w . j a v a 2 s .c o m*/ * @throws CommunicationException * @throws InterruptedException */ private void expectACK() throws CommunicationException, InterruptedException { logger.info("Expecting ACK"); byte ans[] = this.expect(1); ByteBuffer wrapped = ByteBuffer.wrap(ans, 0, ans.length); wrapped.order(ByteOrder.LITTLE_ENDIAN); if (wrapped.get() != DavisReturnCodes.ACK) throw new CommunicationException("Didn't receive ACK"); logger.info("Received ACK successful."); }
From source file:au.org.ala.delta.io.BinaryKeyFile.java
public int writeToRecord(int recordNumber, List<Integer> values) { ByteBuffer bytes = ByteBuffer.allocate(values.size() * SIZE_INT_IN_BYTES); bytes.order(ByteOrder.LITTLE_ENDIAN); for (int value : values) { bytes.putInt(value);//from w w w . j ava 2s .c om } return writeToRecord(recordNumber, 0, bytes.array()); }
From source file:au.org.ala.delta.io.BinaryKeyFile.java
public int writeBooleansToRecord(int recordNumber, List<Boolean> values) { ByteBuffer bytes = ByteBuffer.allocate(values.size() * SIZE_INT_IN_BYTES); bytes.order(ByteOrder.LITTLE_ENDIAN); for (boolean value : values) { bytes.putInt(value ? 1 : 0);/*w w w . ja va2 s. c o m*/ } return writeToRecord(recordNumber, 0, bytes.array()); }
From source file:au.org.ala.delta.io.BinaryKeyFile.java
public int writeFloatsToRecord(int recordNumber, List<Float> values) { ByteBuffer bytes = ByteBuffer.allocate(values.size() * SIZE_INT_IN_BYTES); bytes.order(ByteOrder.LITTLE_ENDIAN); for (float value : values) { bytes.putFloat(value);// w w w . jav a2 s .c o m } return writeToRecord(recordNumber, 0, bytes.array()); }
From source file:au.org.ala.delta.io.BinaryKeyFile.java
/** * Designed to allow headers and index records to be overwritten. * //from w ww .ja v a 2s .co m * @param recordNumber * the first (of possibily many, depending on the number of * values) record to be overwritten. * @param values * the values to write, starting at record, recordNumber.. */ public void overwriteRecord(int recordNumber, List<Integer> values) { if (!_occupiedRecords.contains(recordNumber)) { throw new IllegalArgumentException("Record " + recordNumber + " has not been allocated."); } ByteBuffer bytes = ByteBuffer.allocate(values.size() * SIZE_INT_IN_BYTES); bytes.order(ByteOrder.LITTLE_ENDIAN); for (int value : values) { bytes.putInt(value); } seekToRecord(recordNumber, 0); write(bytes.array()); }
From source file:org.openhab.binding.modbus.internal.ModbusBinding.java
private DecimalType extractStateFromRegisters(InputRegister[] registers, int index, String type) { if (type.equals(ModbusBindingProvider.VALUE_TYPE_BIT)) { return new DecimalType((registers[index / 16].toUnsignedShort() >> (index % 16)) & 1); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_INT8)) { return new DecimalType(registers[index / 2].toBytes()[1 - (index % 2)]); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_UINT8)) { return new DecimalType((registers[index / 2].toUnsignedShort() >> (8 * (index % 2))) & 0xff); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_INT16)) { ByteBuffer buff = ByteBuffer.allocate(2); buff.put(registers[index].toBytes()); return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getShort(0)); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_UINT16)) { return new DecimalType(registers[index].toUnsignedShort()); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_INT32)) { ByteBuffer buff = ByteBuffer.allocate(4); buff.put(registers[index * 2 + 0].toBytes()); buff.put(registers[index * 2 + 1].toBytes()); return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getInt(0)); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_UINT32)) { ByteBuffer buff = ByteBuffer.allocate(8); buff.position(4);/*from w w w .j a v a 2 s.c om*/ buff.put(registers[index * 2 + 0].toBytes()); buff.put(registers[index * 2 + 1].toBytes()); return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getLong(0)); } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_FLOAT32)) { ByteBuffer buff = ByteBuffer.allocate(4); buff.put(registers[index * 2 + 0].toBytes()); buff.put(registers[index * 2 + 1].toBytes()); return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getFloat(0)); } else { throw new IllegalArgumentException(); } }