private int _read(byte[] buffer, int offset, int length) throws IOException { //lifted directly from org.apache.commons.io.IOUtils 2.4 int remaining = length; while (remaining > 0) { int location = length - remaining; int count = read(buffer, offset + location, remaining); if (EOF == count) { // EOF break; } remaining -= count; } return length - remaining; }
public void parse() throws IOException { while (true) { int bInt = is.read(); if (bInt == -1) { return; } readNext((byte) bInt); } }
@Override public int readInt() { byte buf[] = new byte[LittleEndianConsts.INT_SIZE]; try { checkEOF(read(buf), buf.length); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getInt(buf); }
@Override public int readUByte() { byte buf[] = new byte[1]; try { checkEOF(read(buf), 1); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getUByte(buf); }
@Override public long readLong() { byte buf[] = new byte[LittleEndianConsts.LONG_SIZE]; try { checkEOF(read(buf), LittleEndianConsts.LONG_SIZE); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getLong(buf); }
@Override public int readUShort() { byte buf[] = new byte[LittleEndianConsts.SHORT_SIZE]; try { checkEOF(read(buf), LittleEndianConsts.SHORT_SIZE); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getUShort(buf); }
private void nextChunk() throws GeneralSecurityException, IOException { if (chunkSize != -1) { int index = (int)(pos >> chunkBits); initCipherForBlock(cipher, index); if (lastIndex != index) { long skipN = (index - lastIndex) << chunkBits; if (super.skip(skipN) < skipN) { throw new EOFException("buffer underrun"); } } lastIndex = index + 1; } final int todo = (int)Math.min(size, chunk.length); int readBytes, totalBytes = 0; do { readBytes = super.read(plain, totalBytes, todo-totalBytes); totalBytes += Math.max(0, readBytes); } while (readBytes != -1 && totalBytes < todo); if (readBytes == -1 && pos+totalBytes < size && size < Integer.MAX_VALUE) { throw new EOFException("buffer underrun"); } System.arraycopy(plain, 0, chunk, 0, totalBytes); invokeCipher(totalBytes, totalBytes == chunkSize); }
private int _read(byte[] buffer, int offset, int length) throws IOException { //lifted directly from org.apache.commons.io.IOUtils 2.4 int remaining = length; while (remaining > 0) { int location = length - remaining; int count = read(buffer, offset + location, remaining); if (EOF == count) { // EOF break; } remaining -= count; } return length - remaining; }
public void parse() throws IOException { while (true) { int bInt = is.read(); if (bInt == -1) { return; } readNext((byte) bInt); } }
@Override public int readInt() { byte buf[] = new byte[LittleEndianConsts.INT_SIZE]; try { checkEOF(read(buf), buf.length); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getInt(buf); }
@Override public int readUShort() { byte buf[] = new byte[LittleEndianConsts.SHORT_SIZE]; try { checkEOF(read(buf), LittleEndianConsts.SHORT_SIZE); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getUShort(buf); }
@Override public int readUByte() { byte buf[] = new byte[1]; try { checkEOF(read(buf), 1); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getUByte(buf); }
@Override public long readLong() { byte buf[] = new byte[LittleEndianConsts.LONG_SIZE]; try { checkEOF(read(buf), LittleEndianConsts.LONG_SIZE); } catch (IOException e) { throw new RuntimeException(e); } return LittleEndian.getLong(buf); }
private void nextChunk() throws GeneralSecurityException, IOException { if (chunkSize != -1) { int index = (int)(pos >> chunkBits); initCipherForBlock(cipher, index); if (lastIndex != index) { long skipN = (index - lastIndex) << chunkBits; if (super.skip(skipN) < skipN) { throw new EOFException("buffer underrun"); } } lastIndex = index + 1; } final int todo = (int)Math.min(size, chunk.length); int readBytes, totalBytes = 0; do { readBytes = super.read(plain, totalBytes, todo-totalBytes); totalBytes += Math.max(0, readBytes); } while (readBytes != -1 && totalBytes < todo); if (readBytes == -1 && pos+totalBytes < size && size < Integer.MAX_VALUE) { throw new EOFException("buffer underrun"); } System.arraycopy(plain, 0, chunk, 0, totalBytes); invokeCipher(totalBytes, totalBytes == chunkSize); }