public synchronized int read() throws IOException { waitForData(); if (available() == -1) { return -1; } byte b = input[outPointer]; outPointer++; if (outPointer == input.length) { outPointer = 0; } size -= 1; return b; }
@Override public synchronized int read() throws IOException { waitForData(); if (available() == -1) { return -1; } byte b = input[outPointer]; outPointer++; if (outPointer == input.length) { outPointer = 0; } size -= 1; return b; }
public synchronized int read(byte[] b, int off, int len) throws IOException { waitForData(); if (available() == -1) { return -1; } int toCopy = Math.min(len, size); if(input.length-outPointer > toCopy) { System.arraycopy(input, outPointer, b, off, toCopy); outPointer += toCopy; size -= toCopy; } else { int bytesToEnd = input.length-outPointer; System.arraycopy(input, outPointer, b, off, bytesToEnd); System.arraycopy(input, 0, b, off+bytesToEnd, toCopy-bytesToEnd); outPointer = toCopy-bytesToEnd; size -=toCopy; } return toCopy; }
@Override public synchronized int read(byte[] b, int off, int len) throws IOException { waitForData(); if (available() == -1) { return -1; } int toCopy = Math.min(len, size); if(input.length-outPointer > toCopy) { System.arraycopy(input, outPointer, b, off, toCopy); outPointer += toCopy; size -= toCopy; } else { int bytesToEnd = input.length-outPointer; System.arraycopy(input, outPointer, b, off, bytesToEnd); System.arraycopy(input, 0, b, off+bytesToEnd, toCopy-bytesToEnd); outPointer = toCopy-bytesToEnd; size -=toCopy; } return toCopy; }