List of usage examples for java.nio ByteOrder LITTLE_ENDIAN
ByteOrder LITTLE_ENDIAN
To view the source code for java.nio ByteOrder LITTLE_ENDIAN.
Click Source Link
From source file:jGW2API.util.item.Item.java
public String getChatLink() { BASE64Encoder encoder = new BASE64Encoder(); byte[] id = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(this.itemID.intValue()).array(); byte[] toEncode = new byte[id.length + 2]; toEncode[0] = 2;//from w w w. j a v a 2 s . c o m toEncode[1] = 1; for (int i = 2; i < toEncode.length; i++) { toEncode[i] = id[i - 2]; } return "[&" + encoder.encode(toEncode) + "]"; }
From source file:edu.mbl.jif.imaging.mmtiff.MultipageTiffReader.java
public static boolean isMMMultipageTiff(String directory) throws IOException { File dir = new File(directory); File[] children = dir.listFiles(); File testFile = null;/*from www . j a v a 2 s .co m*/ for (File child : children) { if (child.isDirectory()) { File[] grandchildren = child.listFiles(); for (File grandchild : grandchildren) { if (grandchild.getName().endsWith(".tif")) { testFile = grandchild; break; } } } else if (child.getName().endsWith(".tif") || child.getName().endsWith(".TIF")) { testFile = child; break; } } if (testFile == null) { throw new IOException("Unexpected file structure: is this an MM dataset?"); } RandomAccessFile ra; try { ra = new RandomAccessFile(testFile, "r"); } catch (FileNotFoundException ex) { ReportingUtils.logError(ex); return false; } FileChannel channel = ra.getChannel(); ByteBuffer tiffHeader = ByteBuffer.allocate(36); ByteOrder bo; channel.read(tiffHeader, 0); char zeroOne = tiffHeader.getChar(0); if (zeroOne == 0x4949) { bo = ByteOrder.LITTLE_ENDIAN; } else if (zeroOne == 0x4d4d) { bo = ByteOrder.BIG_ENDIAN; } else { throw new IOException("Error reading Tiff header"); } tiffHeader.order(bo); int summaryMDHeader = tiffHeader.getInt(32); channel.close(); ra.close(); if (summaryMDHeader == MultipageTiffWriter.SUMMARY_MD_HEADER) { return true; } return false; }
From source file:com.miraclelinux.historygluon.BridgeWorker.java
public BridgeWorker(Socket socket, StorageDriver driver) { m_socket = socket;/*from ww w. j a v a 2s .c om*/ m_log = LogFactory.getLog(BridgeWorker.class); m_log.info("start BridgeWorker: host: " + m_socket.getInetAddress().getHostAddress() + ", remote port: " + m_socket.getPort()); m_driver = driver; m_byteBuffer = ByteBuffer.allocate(100); m_byteBuffer.order(ByteOrder.LITTLE_ENDIAN); }
From source file:ee.ioc.phon.android.speak.Utils.java
static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) { final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); final Canvas c = new Canvas(b); final Paint paint = new Paint(); paint.setColor(0xFFFFFFFF); // 0xAARRGGBB paint.setAntiAlias(true);/*from www . j av a2 s.c o m*/ paint.setStyle(Paint.Style.STROKE); paint.setAlpha(80); final PathEffect effect = new CornerPathEffect(3); paint.setPathEffect(effect); final int numSamples = waveBuffer.remaining(); int endIndex; if (endPosition == 0) { endIndex = numSamples; } else { endIndex = Math.min(endPosition, numSamples); } int startIndex = startPosition - 2000; // include 250ms before speech if (startIndex < 0) { startIndex = 0; } final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples final float scale = 10.0f / 65536.0f; final int count = (endIndex - startIndex) / numSamplePerWave; final float deltaX = 1.0f * w / count; int yMax = h / 2; Path path = new Path(); c.translate(0, yMax); float x = 0; path.moveTo(x, 0); for (int i = 0; i < count; i++) { final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave); int sign = ((i & 01) == 0) ? -1 : 1; final float y = Math.min(yMax, avabs * h * scale) * sign; path.lineTo(x, y); x += deltaX; path.lineTo(x, y); } if (deltaX > 4) { paint.setStrokeWidth(2); } else { paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05))); } c.drawPath(path, paint); return b; }
From source file:au.org.ala.delta.io.BinFile.java
public ByteBuffer readByteBuffer(int size) { ByteBuffer bb = ByteBuffer.allocate(size); try {//from ww w .j a v a 2 s .c o m int bytesRead = _channel.read(bb); bb.order(ByteOrder.LITTLE_ENDIAN); bb.position(0); assert bytesRead == size; } catch (IOException ioex) { throw new RuntimeException(ioex); } return bb; }
From source file:org.usergrid.mongo.MongoServer.java
public void startServer() { logger.info("Starting Usergrid Mongo Emulation Server"); if (realm != null) { securityManager = new DefaultSecurityManager(realm); }//from w w w .ja v a 2 s . c o m // Configure the server. ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setOption("child.bufferFactory", HeapChannelBufferFactory.getInstance(ByteOrder.LITTLE_ENDIAN)); // Set up the pipeline factory. ExecutionHandler executionHandler = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)); bootstrap.setPipelineFactory( new MongoServerPipelineFactory(emf, smf, management, securityManager, executionHandler)); // Bind and start to accept incoming connections. channel = bootstrap.bind(new InetSocketAddress(27017)); logger.info("Usergrid Mongo API Emulation Server accepting connections..."); }
From source file:org.jmangos.sniffer.network.model.impl.WOWNetworkChannel.java
@Override synchronized public void onResiveServerData(final long frameNumber, final byte[] buffer) { final ByteBuffer bytebuf = ByteBuffer.wrap(buffer); bytebuf.order(ByteOrder.LITTLE_ENDIAN); long opcode = 0; long size = 0; byte[] data = null; if (getChannelState().contains(State.AUTHED)) { final long header = bytebuf.getInt() & 0xFFFFFFFF; size = header >> 13;// ww w . j a v a 2 s .c o m opcode = header & 0x1FFF; data = new byte[(int) size]; bytebuf.get(data); } else { size = bytebuf.getShort(); opcode = bytebuf.getInt(); bytebuf.mark(); data = new byte[(int) size - 4]; bytebuf.get(data); bytebuf.reset(); // old 0xc0b if ((opcode == 0x221) & !getChannelState().contains(State.NOT_ACCEPT_SEED)) { this.log.debug("Get new Seed"); final byte[] serverSeed = new byte[16]; final byte[] clientSeed = new byte[16]; for (int i = 0; i < 16; i++) { serverSeed[i] = bytebuf.get(); } for (int i = 0; i < 16; i++) { clientSeed[i] = bytebuf.get(); } bytebuf.get(); this.csPacketBuffer.getCrypt().setEncryptionSeed(clientSeed); this.scPacketBuffer.getCrypt().setEncryptionSeed(serverSeed); } } this.log.debug(String.format("Frame: %d; Resive packet %s Opcode: 0x%x OpcodeSize: %d", frameNumber, "SMSG", opcode, size)); for (final PacketLogHandler logger : this.packetLoggers) { logger.onDecodePacket(this, Direction.SERVER, (int) size, (int) opcode, data, (int) frameNumber); } }
From source file:org.datavec.image.loader.NativeImageLoader.java
static Mat convert(PIX pix) { PIX tempPix = null;//from ww w .j a v a 2s . c om if (pix.colormap() != null) { PIX pix2 = pixRemoveColormap(pix, REMOVE_CMAP_TO_FULL_COLOR); tempPix = pix = pix2; } else if (pix.d() < 8) { PIX pix2 = null; switch (pix.d()) { case 1: pix2 = pixConvert1To8(null, pix, (byte) 0, (byte) 255); break; case 2: pix2 = pixConvert2To8(pix, (byte) 0, (byte) 85, (byte) 170, (byte) 255, 0); break; case 4: pix2 = pixConvert4To8(pix, 0); break; default: assert false; } tempPix = pix = pix2; } int height = pix.h(); int width = pix.w(); int channels = pix.d() / 8; Mat mat = new Mat(height, width, CV_8UC(channels), pix.data(), 4 * pix.wpl()); Mat mat2 = new Mat(height, width, CV_8UC(channels)); // swap bytes if needed int[] swap = { 0, 3, 1, 2, 2, 1, 3, 0 }, copy = { 0, 0, 1, 1, 2, 2, 3, 3 }, fromTo = channels > 1 && ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN) ? swap : copy; mixChannels(mat, 1, mat2, 1, fromTo, fromTo.length / 2); if (tempPix != null) { pixDestroy(tempPix); } return mat2; }
From source file:com.esri.core.geometry.GeometryEngine.java
/** * Imports geometry from the ESRI shape file format. * /*from w ww . j av a 2 s. c o m*/ * @param esriShapeBuffer * The buffer containing geometry in the ESRI shape file format. * @param geometryType * The required type of the Geometry to be imported. Use * Geometry.Type.Unknown if the geometry type needs to be * determined from the buffer content. * @return The geometry or null if the buffer contains null shape. * @throws GeometryException * when the geometryType is not Geometry.Type.Unknown and the * buffer contains geometry that cannot be converted to the * given geometryType. or the buffer is corrupt. Another * exception possible is IllegalArgumentsException. */ public static Geometry geometryFromEsriShape(byte[] esriShapeBuffer, Geometry.Type geometryType) { OperatorImportFromESRIShape op = (OperatorImportFromESRIShape) factory .getOperator(Operator.Type.ImportFromESRIShape); return op.execute(ShapeImportFlags.ShapeImportNonTrusted, geometryType, ByteBuffer.wrap(esriShapeBuffer).order(ByteOrder.LITTLE_ENDIAN)); }
From source file:com.tesora.dve.db.mysql.DBTypeBasedUtilsTest.java
@Test public void mysqlReadWriteTest() throws Exception { ByteBuf cb = Unpooled.buffer(100).order(ByteOrder.LITTLE_ENDIAN); int len;/*from w ww . ja va 2 s . c om*/ for (Pair<MyFieldType, Object> expValue : expValuesMysql) { cb.clear(); len = 0; if (expValue.getSecond() instanceof Byte) len = 1; DataTypeValueFunc dtvf = DBTypeBasedUtils.getMysqlTypeFunc(expValue.getFirst(), len, 0); dtvf.writeObject(cb, expValue.getSecond()); assertEqualData(expValue.getSecond(), dtvf.readObject(cb)); } }