List of usage examples for java.nio ByteOrder nativeOrder
public static ByteOrder nativeOrder()
From source file:org.apache.tajo.tuple.BaseTupleBuilder.java
public BaseTupleBuilder(Schema schema) { super(SchemaUtil.toDataTypes(schema)); buffer = ByteBuffer.allocateDirect(64 * StorageUnit.KB).order(ByteOrder.nativeOrder()); address = UnsafeUtil.getAddress(buffer); }
From source file:org.apache.tajo.tuple.offheap.OffHeapMemory.java
public OffHeapMemory(ResizableLimitSpec limitSpec) { this(ByteBuffer.allocateDirect((int) limitSpec.initialSize()).order(ByteOrder.nativeOrder()), limitSpec); }
From source file:io.pcp.parfait.dxm.FileByteBufferFactory.java
public ByteBuffer build(int length) throws IOException { RandomAccessFile fos = null;/*from w w w. ja va2 s.c om*/ try { File parent = file.getParentFile(); if (parent == null) { throw new RuntimeException("Could not find parent of output file " + file.getCanonicalPath()); } else if (parent.exists()) { file.delete(); /* directory update visible to MMV PMDA */ if (file.exists()) { throw new RuntimeException("Could not delete existing file " + file.getCanonicalPath()); } } else if (!parent.mkdirs()) { throw new RuntimeException("Could not create output directory " + parent.getCanonicalPath()); } fos = new RandomAccessFile(file, "rw"); fos.setLength(length); ByteBuffer tempDataFile = fos.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length); tempDataFile.order(ByteOrder.nativeOrder()); fos.close(); return tempDataFile; } finally { if (fos != null) { fos.close(); } } }
From source file:de.ailis.threedee.utils.BufferUtils.java
/** * Converts the specified float buffer to native endian and returns this new * buffer. If buffer is already in correct endian format then it is returned * right away.//from ww w .j a v a 2 s .co m * * @param buffer * The float buffer to convert * @return The converted float buffer or the source buffer if no conversion * is needed */ public static FloatBuffer convertToNativeEndian(final FloatBuffer buffer) { if (buffer.order() == ByteOrder.nativeOrder()) return buffer; if (log.isTraceEnabled()) log.trace("Converting endianess of " + buffer.capacity() + " floats"); final ByteBuffer bytes = ByteBuffer.allocateDirect(buffer.capacity()); bytes.order(ByteOrder.nativeOrder()); final FloatBuffer floats = bytes.asFloatBuffer(); floats.put(buffer).rewind(); return floats; }
From source file:Main.java
public static DoubleBuffer createDoubleBuffer(final int size) { final DoubleBuffer buf = ByteBuffer.allocateDirect(8 * size).order(ByteOrder.nativeOrder()) .asDoubleBuffer();//from w ww . j a v a2s.co m buf.clear(); return buf; }
From source file:org.energy_home.jemma.osgi.ah.io.flexgateway.FlexGatewayButtons.java
public void run() { long tv_sec;/*from w ww .j a v a 2s . c om*/ long tv_usec; short type; short code; int value; while (true) { buttonFile = new File(flexGatewayButtonsDevice); ByteBuffer buffer = ByteBuffer.allocate(100); buffer.order(ByteOrder.nativeOrder()); try { fis = new FileInputStream(buttonFile); channel = fis.getChannel(); while (true) { buffer.clear(); int size = channel.read(buffer); buffer.rewind(); while (size > 0) { tv_sec = buffer.getInt(); tv_usec = buffer.getInt(); long tv = tv_sec * 1000000 + tv_usec; type = buffer.getShort(); code = buffer.getShort(); value = buffer.getInt(); size -= 16; if (type == 0 && code == 0 && value == 0) continue; // Code 3 -> front button // Code 2 -> back button // Value > 0 -> button pressed // Value > 0 -> button released // send event log.debug("Button: ms " + tv + " type " + (type & 0xffff) + " code " + (code & 0xffff) + " value " + (value & 0xffffffff)); Hashtable props = new Hashtable(); props.put("timestamp", new Long(tv)); if (value > 0) this.postEvent("button/" + code + "/UP", props); else this.postEvent("button/" + code + "/DOWN", props); } } } catch (ClosedByInterruptException e) { break; } catch (IOException e) { // TODO Auto-generated catch block log.error("exception", e); break; } finally { try { if (channel != null) channel.close(); } catch (IOException e) { log.error("exception", e); break; } } } log.debug("exiting"); }
From source file:org.ballerinalang.stdlib.io.data.DataInputOutputTest.java
@Test(description = "Test fixed long value ranges", dataProvider = "SignedLongValues") public void testSignedFixedLong(long value, Representation representation) throws IOException, URISyntaxException { String filePath = currentDirectoryPath + "/sample.bin"; ByteChannel byteChannel = TestUtil.openForReadingAndWriting(filePath); Channel channel = new MockByteChannel(byteChannel); DataChannel dataChannel = new DataChannel(channel, ByteOrder.nativeOrder()); dataChannel.writeLong(value, representation); channel.close();/*from w w w . j av a 2 s . c o m*/ byteChannel = TestUtil.openForReadingAndWriting(filePath); channel = new MockByteChannel(byteChannel); dataChannel = new DataChannel(channel, ByteOrder.nativeOrder()); long readInt = dataChannel.readLong(representation).getValue(); Assert.assertEquals(readInt, value); }
From source file:edu.csun.ecs.cs.multitouchj.ui.control.Canvas.java
protected ByteBuffer prepareImage(Image image) { ByteBuffer imageData = ByteBuffer.allocateDirect(image.getData().length).order(ByteOrder.nativeOrder()); imageData.put(image.getData());/*from w w w . j a v a2 s . com*/ imageData.flip(); return imageData; }
From source file:github.daneren2005.serverproxy.ServerProxy.java
public String getPublicAddress(String request) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }// ww w .ja v a2s. c o m byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray(); String ipAddressString = null; try { ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress(); } catch (UnknownHostException ex) { Log.e(TAG, "Unable to get host address."); } return getAddress(ipAddressString, request); }
From source file:de.ailis.threedee.utils.BufferUtils.java
/** * Converts the specified short buffer to native endian and returns this new * buffer. If buffer is already in correct endian format then it is returned * right away./*ww w . j a v a 2 s .co m*/ * * @param buffer * The short buffer to convert * @return The converted short buffer or the source buffer if no conversion * is needed */ public static ShortBuffer convertToNativeEndian(final ShortBuffer buffer) { if (buffer.order() == ByteOrder.nativeOrder()) return buffer; final ByteBuffer bytes = ByteBuffer.allocateDirect(buffer.capacity()); bytes.order(ByteOrder.nativeOrder()); final ShortBuffer shorts = bytes.asShortBuffer(); shorts.put(buffer).rewind(); return shorts; }