/** * Get several bytes from the queue (size can be any positive). Blocks until specified number of * bytes are written. */ public byte[] get(int size) { byte[] result = new byte[size]; for (int i = 0; i < size; i++) { result[i] = (byte)get(); } return result; }
/** * Get all data available from the buffer * @return */ public byte[] readAll() { synchronized (access) { int size = getAvailable(); byte[] result = new byte[size]; for( int i=0; i<size; i++) result[i] = (byte) get(); return result; } }
/** * Nonblocking get the next byte. * * @return -1 of there is no data or the next available byte. */ public int read() { synchronized (access) { if (rpos == wpos) return -1; return get(); } }
/** * Read bytes from the buffer, blocking untili available, and convert them to the UTF-8 string * * @param size string exact size */ public String getString(int size) { return new String(get(size)); }
@Override public int read() throws IOException { if( closed.get() ) { close(); return -1; } return buffer.get(); }
@Override public int read() throws IOException { int nextByte = inputStream.read(); if (nextByte < 0) { readingFinished = true; end(); return -1; } else { ring.put(nextByte); try { int encrypted = ring.get(); hmac.update(encrypted); return transformer.transformByte(encrypted); } catch (EncryptionError encryptionError) { throw new IOException("failed to decrypt", encryptionError); } } }