List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
static void nextRowOfFloats(float[] row, String datatype, boolean byteOrderLSB, int ncols, RandomAccessFile raf, byte[] b, float noDataValue) throws IOException { int size = 4; if (datatype.charAt(0) == 'U') { size = 1;// w w w.j a va 2 s . co m } else if (datatype.charAt(0) == 'B') { size = 1; } else if (datatype.charAt(0) == 'S') { size = 2; } else if (datatype.charAt(0) == 'I') { size = 4; } else if (datatype.charAt(0) == 'L') { size = 8; } else if (datatype.charAt(0) == 'F') { size = 4; } else if (datatype.charAt(0) == 'D') { size = 8; } raf.read(b, 0, size * ncols); ByteBuffer bb = ByteBuffer.wrap(b); if (byteOrderLSB) { bb.order(ByteOrder.LITTLE_ENDIAN); } else { bb.order(ByteOrder.BIG_ENDIAN); } int i; int length = ncols; if (datatype.charAt(0) == 'U') { for (i = 0; i < length; i++) { float ret = bb.get(); if (ret < 0) { ret += 256; } row[i] = ret; } } else if (datatype.charAt(0) == 'B') { for (i = 0; i < length; i++) { row[i] = (float) bb.get(); } } else if (datatype.charAt(0) == 'S') { for (i = 0; i < length; i++) { row[i] = (float) bb.getShort(); } } else if (datatype.charAt(0) == 'I') { for (i = 0; i < length; i++) { row[i] = (float) bb.getInt(); } } else if (datatype.charAt(0) == 'L') { for (i = 0; i < length; i++) { row[i] = (float) bb.getLong(); } } else if (datatype.charAt(0) == 'F') { for (i = 0; i < length; i++) { row[i] = (float) bb.getFloat(); } } else if (datatype.charAt(0) == 'D') { for (i = 0; i < length; i++) { row[i] = (float) bb.getDouble(); } } else { logger.info("UNKNOWN TYPE: " + datatype); } for (i = 0; i < length; i++) { if (row[i] == noDataValue) { row[i] = Float.NaN; } } }
From source file:com.torchmind.authenticator.AbstractTokenGenerator.java
/** * Generates a code based on a secret key and challenge. * * @param secretKey a secret key.//from w w w. j a v a 2 s . c o m * @param challenge a challenge. * @return a code. */ @NonNull protected String generateCode(@NonNull SecretKey secretKey, @NonNull byte[] challenge) { try { Mac mac = Mac.getInstance("Hmac" + this.algorithm.name()); mac.init(secretKey); byte[] hash = mac.doFinal(challenge); int offset = hash[hash.length - 1] & 0x0F; ByteBuffer buffer = ByteBuffer.allocate(4).put(hash, offset, 4); buffer.flip(); return String.format("%0" + this.digits + "d", (buffer.getInt() & 0x7FFFFFFF) % this.digitModulo); } catch (NoSuchAlgorithmException ex) { throw new UnsupportedOperationException( "The specified algorithm is not supported by this Java VM implementation: " + ex.getMessage(), ex); } catch (InvalidKeyException ex) { throw new IllegalArgumentException("Invalid shared secret: " + ex.getMessage(), ex); } }
From source file:org.cosmo.common.file.VariableFilePartition.java
public void checkIncompleteWrite(File readFile) throws FileNotFoundException, IOException, IncompleteWriteException { for (int i = 0; i < _readChannels.length; i++) { long size = _readChannels[i].size(); if (size > MetaBytes) { // there is data ByteBuffer buf = ByteBuffer.wrap(new byte[4]); _readChannels[i].read(buf, _readChannels[i].size() - 4); buf.rewind();/*from ww w . j av a 2 s. c o m*/ int marker = buf.getInt(); if (marker != StoreCompleteMarker) { throw new IncompleteWriteException(New.str("File [", Util.addSuffixToFile(readFile, i), "] did not complete last write operation")); } } } }
From source file:com.github.horrorho.inflatabledonkey.data.blob.BlobA6.java
public BlobA6(ByteBuffer blob) { super(blob);/*from w w w . ja va 2 s . co m*/ if (type() != 0x000000A6) { // Presumed type 0x000000A6, consider throwing exception. logger.warn("** RespA6() - unexpected type: 0x{}", Integer.toHexString(type())); } x = blob.getInt(); blob.get(tag); align(blob); list = new BlobLists(blob); if (list.size() < 3) { throw new IllegalArgumentException("too few blob fields: " + list.size()); } }
From source file:com.cellngine.crypto.RSACipher.java
private BigInteger[] getKeyData(final byte[] fromBytes) { final ByteBuffer buffer = ByteBuffer.wrap(fromBytes); final int modulusLength = buffer.getInt(); final byte[] modulusBuffer = new byte[modulusLength]; buffer.get(modulusBuffer);/*from ww w .j av a 2s .c o m*/ final BigInteger modulus = new BigInteger(modulusBuffer); final int exponentLength = buffer.getInt(); final byte[] exponentBuffer = new byte[exponentLength]; buffer.get(exponentBuffer); final BigInteger exponent = new BigInteger(exponentBuffer); return new BigInteger[] { modulus, exponent }; }
From source file:com.tc.simple.apn.factories.FeedbackFactory.java
public List<Feedback> createFeedback(InputStream in) { List<Feedback> list = new ArrayList<Feedback>(); try {//from w w w.j a v a 2s . c o m byte[] byteMe = IOUtils.toByteArray(in); int startRange = 0; int endRange = 38; //38 byte chunks per feedback item. while (startRange < byteMe.length) { //init the value object to hold the feedback data. Feedback feedback = new Feedback(); //build the item based on range byte[] item = Arrays.copyOfRange(byteMe, startRange, endRange);//38 byte chunks. byte[] date = Arrays.copyOfRange(item, 0, 4); byte[] size = Arrays.copyOfRange(item, 4, 6); byte[] token = Arrays.copyOfRange(item, 6, item.length); ByteBuffer dateWrap = ByteBuffer.wrap(date); ByteBuffer javaSize = ByteBuffer.wrap(size); //set the date (returns number of seconds from unix epoch date) feedback.setDate(new Date(dateWrap.getInt() * 1000L)); //get the size of the token (should always be 32) feedback.setSize(javaSize.getShort()); //drop in our encoded token (will be used as our key for marking the user's token doc as failed) feedback.setToken(String.valueOf(Hex.encodeHex(token))); //add it to our collection list.add(feedback); //increment the start range startRange = startRange + 38; //increment the end range. endRange = endRange + 38; } } catch (Exception e) { logger.log(Level.SEVERE, null, e); } return list; }
From source file:net.jenet.CommandHeader.java
public void fromBuffer(ByteBuffer buffer) { command = buffer.get();//from w w w . j av a2s . c o m channelID = buffer.get(); flags = buffer.get(); reserved = buffer.get(); commandLength = buffer.getInt(); reliableSequenceNumber = buffer.getInt(); }
From source file:xbird.server.services.RemotePagingService.java
/** * @return is closeable?/*from w w w . jav a 2 s . com*/ */ private void doWrite(final SocketChannel socketChannel, final ByteBuffer cmdBuffer) { // receive a command cmdBuffer.flip(); final int cmd = cmdBuffer.getInt(); switch (cmd) { case COMMAND_READ: RemoteMemoryMappedFile.sendback(socketChannel, cmdBuffer, _fdCacheMap, _sndBufDTM); break; case COMMAND_TRACK_READ: RemoteVarSegments.sendback(socketChannel, cmdBuffer, _fdCacheMap, _directoryCache, _sndBufSegm); break; default: throw new IllegalStateException("Unknown command: " + cmd); } }
From source file:edu.umn.cs.spatialHadoop.visualization.FrequencyMap.java
@Override public void readFields(DataInput in) throws IOException { super.readFields(in); int length = in.readInt(); byte[] serializedData = new byte[length]; in.readFully(serializedData);//w w w. j a va 2 s . c o m ByteArrayInputStream bais = new ByteArrayInputStream(serializedData); GZIPInputStream gzis = new GZIPInputStream(bais); byte[] buffer = new byte[8]; gzis.read(buffer); ByteBuffer bbuffer = ByteBuffer.wrap(buffer); int width = bbuffer.getInt(); int height = bbuffer.getInt(); // Reallocate memory only if needed if (width != this.getWidth() || height != this.getHeight()) frequencies = new float[width][height]; buffer = new byte[getHeight() * 4]; for (int x = 0; x < getWidth(); x++) { int size = 0; while (size < buffer.length) { size += gzis.read(buffer, size, buffer.length - size); } bbuffer = ByteBuffer.wrap(buffer); for (int y = 0; y < getHeight(); y++) { frequencies[x][y] = bbuffer.getFloat(); } } }
From source file:com.github.horrorho.inflatabledonkey.data.blob.BlobA0.java
public BlobA0(ByteBuffer blob) { super(blob);/*from www .ja v a 2s . c o m*/ if (type() != 0x000000A0) { // Presumed type 0x000000A0, consider throwing exception. logger.warn("** BlobA0() - unexpected type: 0x{}", Integer.toHexString(type())); } x = blob.getInt(); iterations = blob.getInt(); y = blob.getInt(); list = new BlobLists(blob); if (list.size() < 5) { throw new IllegalArgumentException("too few blob fields: " + list.size()); } label = new String(list.get(4), UTF_8); timestamp = list.size() > 5 ? new String(list.get(5), UTF_8) : ""; }