/** * Gets 4 bytes from byte list as an integer. * * @param i Index into the byte list. * @return Integer starting at index location. */ public int getInt(int i) { assert i + 4 <= size; return U.bytesToInt(data, i); }
/** {@inheritDoc} */ @Override public long requestId() { return U.bytesToInt(opaque, 0); }
return bytes[0] == '1'; case INT_FLAG: return U.bytesToInt(bytes, 0); case LONG_FLAG: return U.bytesToLong(bytes, 0); return bytes[0]; case FLOAT_FLAG: return Float.intBitsToFloat(U.bytesToInt(bytes, 0)); case DOUBLE_FLAG: return Double.longBitsToDouble(U.bytesToLong(bytes, 0));
/** * @param po Binary object. * @param off Offset. * @return Value. */ private int intFromBinary(BinaryObject po, int off) { byte[] arr = U.field(po, "arr"); return Integer.reverseBytes(U.bytesToInt(arr, off)); }
/** * @param in Input stream. * @return Checkpoint data. * @throws IOException In case of error. */ public static S3CheckpointData fromStream(InputStream in) throws IOException { byte[] buf = new byte[8]; read(in, buf, 4); byte[] state = new byte[U.bytesToInt(buf, 0)]; read(in, state, state.length); read(in, buf, 8); long expTime = U.bytesToLong(buf, 0); read(in, buf, 4); byte[] keyBytes = new byte[U.bytesToInt(buf, 0)]; read(in, keyBytes, keyBytes.length); return new S3CheckpointData(state, expTime, new String(keyBytes)); }
/** * Reads prefixed bytes from socket input stream. Note that this method may block forever if there is * not enough bytes available in socket input stream. * * @return Read bytes. * @throws IOException If read failed or stream has been closed before full message has been read. */ public byte[] receiveMessage() throws IOException { byte[] prefix = new byte[4]; int idx = 0; while (idx < 4) { int read = in.read(prefix, idx, 4 - idx); if (read < 0) throw new IOException("End of stream reached before message length was read."); idx += read; } int len = U.bytesToInt(prefix, 0); byte[] res = new byte[len]; idx = 0; while (idx < len) { int read = in.read(res, idx, len - idx); if (read < 0) throw new IOException("End of stream reached before message body was read."); idx += read; } return res; }
/** * @param in Input stream to read from. * @return Read message. * @throws IOException If connection closed or packet was incorrect. */ private static byte[] readMessage(InputStream in) throws IOException { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); for (int i = 0; i < 4; i++) { int symbol = in.read(); if (symbol == -1) throw new IOException("Connection was closed."); tmp.write(symbol); } int length = U.bytesToInt(tmp.toByteArray(), 0); tmp.reset(); for (int i = 0; i < length; i++) { int symbol = in.read(); if (symbol == -1) throw new IOException("Connection was closed."); if ((byte)symbol != (byte)i) throw new IOException("Invalid packet: mismatch in position " + i); tmp.write(symbol); } return tmp.toByteArray(); }
return bytes[0] == '1'; case INT_FLAG: return U.bytesToInt(bytes, 0); case LONG_FLAG: return U.bytesToLong(bytes, 0); return bytes[0]; case FLOAT_FLAG: return Float.intBitsToFloat(U.bytesToInt(bytes, 0)); case DOUBLE_FLAG: return Double.longBitsToDouble(U.bytesToLong(bytes, 0));
resType = U.bytesToInt(hdr, 0);
len = U.bytesToInt(lenBytes, 0);
req.totalLength(U.bytesToInt(tmp.toByteArray(), 0));
totalLength = U.bytesToInt(buf.toByteArray(), 0); opaque = U.bytesToInt(buf.toByteArray(), 0);
IgfsIpcCommand cmd = IgfsIpcCommand.valueOf(U.bytesToInt(hdr, 8)); int blockLen = U.bytesToInt(msgHdr, 5);
ses + ", opCode=" + Integer.toHexString(req.operationCode() & 0xFF) + ']'); req.expiration(U.bytesToInt(extras, 4) & 0xFFFFFFFFL);
len = U.bytesToInt(buf.toByteArray(), 0);
req.length(U.bytesToInt(hdr, 20));
int ordinal = U.bytesToInt(hdr, 8);
/** * Gets 4 bytes from byte list as an integer. * * @param i Index into the byte list. * @return Integer starting at index location. */ public int getInt(int i) { assert i + 4 <= size; return U.bytesToInt(data, i); }
/** {@inheritDoc} */ @Override public long requestId() { return U.bytesToInt(opaque, 0); }
/** * @param in Input stream. * @return Checkpoint data. * @throws IOException In case of error. */ public static S3CheckpointData fromStream(InputStream in) throws IOException { byte[] buf = new byte[8]; read(in, buf, 4); byte[] state = new byte[U.bytesToInt(buf, 0)]; read(in, state, state.length); read(in, buf, 8); long expTime = U.bytesToLong(buf, 0); read(in, buf, 4); byte[] keyBytes = new byte[U.bytesToInt(buf, 0)]; read(in, keyBytes, keyBytes.length); return new S3CheckpointData(state, expTime, new String(keyBytes)); }