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:org.jtransforms.fft.DoubleFFT_1DTest.java
/** * Read the binary reference data files generated with FFTW. The structure * of these files is very simple: double values are written linearly (little * endian)./* ww w . j a va 2 s .c om*/ * * @param name * the file name * @param data * the array to be updated with the data read (the size of this * array gives the number of <code>double</code> to be retrieved */ public void readData(final String name, final double[] data) { try { final File f = new File(getClass().getClassLoader().getResource(name).getFile()); final FileInputStream fin = new FileInputStream(f); final FileChannel fc = fin.getChannel(); final ByteBuffer buffer = ByteBuffer.allocate(8 * data.length); buffer.order(ByteOrder.LITTLE_ENDIAN); fc.read(buffer); for (int i = 0; i < data.length; i++) { data[i] = buffer.getDouble(8 * i); } } catch (IOException e) { Assert.fail(e.getMessage()); } }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
public static ArrayList<Integer> locateLengthCodedStrings(ByteBuf cb, int skipAmount) { ArrayList<Integer> offsets = new ArrayList<>(); ByteBuf slice = cb.slice().order(ByteOrder.LITTLE_ENDIAN); slice.skipBytes(skipAmount);/*from w ww . j av a 2s . com*/ while (slice.isReadable()) { offsets.add(slice.readerIndex()); skipLengthCodedString(slice); } return offsets; }
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//from w w w.j a v a2 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// w w w . j ava 2s .co 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:nl.salp.warcraft4j.casc.cdn.local.LocalIndexFileParser.java
/** * Read and parse the index file header. * * @param reader The reader to read the header data from. * * @return The parsed index file header. * * @throws CascParsingException When the header is invalid. * @throws DataReadingException When reading the entry data failed. * @throws DataParsingException When parsing the entry data failed. *//*from ww w . ja va2 s .c o m*/ private IndexHeaderV2 parseHeader(DataReader reader) throws CascParsingException, DataReadingException, DataParsingException { int indexVersion = reader.readNext(DataTypeFactory.getUnsignedShort(), ByteOrder.LITTLE_ENDIAN); if (indexVersion != 0x07) { throw new CascParsingException( format("Invalid index file header version 0x%02X, requires 0x07", indexVersion)); } byte keyIndex = reader.readNext(DataTypeFactory.getByte()); byte extraBytes = reader.readNext(DataTypeFactory.getByte()); byte spanSizeBytes = reader.readNext(DataTypeFactory.getByte()); byte spanOffsetBytes = reader.readNext(DataTypeFactory.getByte()); byte keyBytes = reader.readNext(DataTypeFactory.getByte()); byte segmentBits = reader.readNext(DataTypeFactory.getByte()); long maxFileOffset = reader.readNext(DataTypeFactory.getLong(), ByteOrder.BIG_ENDIAN); if (extraBytes != 0x00 || spanSizeBytes != 0x04 || spanOffsetBytes != 0x05 || keyBytes != 0x09) { throw new CascParsingException("Invalid index file header"); } return new IndexHeaderV2(indexVersion, keyIndex, extraBytes, spanSizeBytes, spanOffsetBytes, keyBytes, segmentBits, maxFileOffset); }
From source file:com.sanlq.common.IPIP.java
private void loadToTree() { FileInputStream fin = null;/*from w w w .ja va 2s . c om*/ lock.lock(); try { if (IPDB_FILE_CONTENT == null) { IPDB_FILE_CONTENT = readHDFSFile("/data/lib/ipip/ipdb.dat"); } if (IPDB_FILE_CONTENT != null) { dataBuffer = ByteBuffer.allocate(Long.valueOf(IPDB_FILE_CONTENT.length).intValue()); dataBuffer.put(IPDB_FILE_CONTENT); dataBuffer.position(0); int indexLength = dataBuffer.getInt(); byte[] indexBytes = new byte[indexLength]; dataBuffer.get(indexBytes, 0, indexLength - 4); indexBuffer = ByteBuffer.wrap(indexBytes); indexBuffer.order(ByteOrder.LITTLE_ENDIAN); offset = indexLength; int loop = 0; while (loop++ < 256) { index[loop - 1] = indexBuffer.getInt(); } indexBuffer.order(ByteOrder.BIG_ENDIAN); } } finally { lock.unlock(); } }
From source file:au.org.ala.delta.io.BinFile.java
public void writeBytes(byte[] buffer) { try {//from w ww . java 2s.com ByteBuffer bb = ByteBuffer.allocate(buffer.length); bb.order(ByteOrder.LITTLE_ENDIAN); bb.put(buffer); bb.position(0); _channel.write(bb); // _file.write(buffer); } catch (IOException ioex) { throw new RuntimeException(ioex); } }
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 a va 2 s . c om } return writeToRecord(recordNumber, 0, bytes.array()); }
From source file:ome.io.bioformats.BfPyramidPixelBuffer.java
private synchronized void initializeReader() throws IOException, FormatException { if (isLockedByOthers()) { throw new LockTimeout(String.format("%s is locked by others", readerFile.getAbsolutePath()), 15 * 1000, 0);/*from w ww. j av a 2 s .c o m*/ } reader = new OmeroPixelsPyramidReader(); delegate = new BfPixelBuffer(readerFile.getAbsolutePath(), reader); byteOrder = delegate.isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN; }
From source file:ffx.xray.MTZFilter.java
/** * {@inheritDoc}//from w ww . ja v a 2 s.com */ @Override public ReflectionList getReflectionList(File mtzFile, CompositeConfiguration properties) { ByteOrder b = ByteOrder.nativeOrder(); FileInputStream fis; DataInputStream dis; try { fis = new FileInputStream(mtzFile); dis = new DataInputStream(fis); byte headeroffset[] = new byte[4]; byte bytes[] = new byte[80]; int offset = 0; // eat "MTZ" title dis.read(bytes, offset, 4); String mtzstr = new String(bytes); // header offset dis.read(headeroffset, offset, 4); // machine stamp dis.read(bytes, offset, 4); ByteBuffer bb = ByteBuffer.wrap(bytes); int stamp = bb.order(ByteOrder.BIG_ENDIAN).getInt(); String stampstr = Integer.toHexString(stamp); switch (stampstr.charAt(0)) { case '1': case '3': if (b.equals(ByteOrder.LITTLE_ENDIAN)) { b = ByteOrder.BIG_ENDIAN; } break; case '4': if (b.equals(ByteOrder.BIG_ENDIAN)) { b = ByteOrder.LITTLE_ENDIAN; } break; } bb = ByteBuffer.wrap(headeroffset); int headeroffseti = bb.order(b).getInt(); // skip to header and parse dis.skipBytes((headeroffseti - 4) * 4); for (Boolean parsing = true; parsing; dis.read(bytes, offset, 80)) { mtzstr = new String(bytes); parsing = parseHeader(mtzstr); } } catch (EOFException eof) { System.out.println("EOF reached "); } catch (IOException ioe) { System.out.println("IO Exception: " + ioe.getMessage()); return null; } // column identifiers foString = sigfoString = rfreeString = null; if (properties != null) { foString = properties.getString("fostring", null); sigfoString = properties.getString("sigfostring", null); rfreeString = properties.getString("rfreestring", null); } h = k = l = fo = sigfo = rfree = -1; fplus = sigfplus = fminus = sigfminus = rfreeplus = rfreeminus = -1; fc = phic = -1; boolean print = false; parseColumns(print); parseFcColumns(print); if (fo < 0 && fplus < 0 && sigfo < 0 && sigfplus < 0 && fc < 0 && phic < 0) { logger.info( " The MTZ header contains insufficient information to generate the reflection list.\n For non-default column labels set fostring/sigfostring in the properties file."); return null; } Column c; if (fo > 0) { c = (Column) columns.get(fo); } else if (fplus > 0) { c = (Column) columns.get(fplus); } else { c = (Column) columns.get(fc); } Dataset d = (Dataset) datasets.get(c.id - dsetoffset); if (logger.isLoggable(Level.INFO)) { StringBuilder sb = new StringBuilder(); sb.append(String.format("\n Reading %s\n\n", mtzFile.getName())); sb.append(String.format(" Setting up reflection list based on MTZ file.\n")); sb.append(String.format(" Space group number: %d (name: %s)\n", sgnum, SpaceGroup.spaceGroupNames[sgnum - 1])); sb.append(String.format(" Resolution: %8.3f\n", 0.999999 * resHigh)); sb.append(String.format(" Cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", d.cell[0], d.cell[1], d.cell[2], d.cell[3], d.cell[4], d.cell[5])); logger.info(sb.toString()); } Crystal crystal = new Crystal(d.cell[0], d.cell[1], d.cell[2], d.cell[3], d.cell[4], d.cell[5], SpaceGroup.spaceGroupNames[sgnum - 1]); double sampling = 0.6; if (properties != null) { sampling = properties.getDouble("sampling", 0.6); } Resolution resolution = new Resolution(0.999999 * resHigh, sampling); return new ReflectionList(crystal, resolution, properties); }