Refine search
public void readFully (byte[] b, int off, int len) throws IOException { while (len > 0) { int count = is.read(b, off, len); if (count <= 0) { throw new EOFException(); } off += count; len -= count; } }
/** * Handle End of File. * * @return <code>-1</code> if <code>throwEofException</code> is * set to {@code false} * @throws EOFException if <code>throwEofException</code> is set * to {@code true}. */ private int doEndOfFile() throws EOFException { eof = true; if (throwEofException) { throw new EOFException(); } return EOF; }
private void skipFully (int count) throws IOException { while (count > 0) { long skipped = in.skip(count); if (skipped <= 0) throw new EOFException("Unable to skip."); count -= skipped; } }
@Test public void eofExceptionProvidesLimitedContent() throws IOException { data.writeUtf8("aaaaaaaabbbbbbbbccccccccdddddddde"); try { source.readUtf8LineStrict(); fail(); } catch (EOFException expected) { assertEquals("\\n not found: limit=33 content=616161616161616162626262626262626363636363636363" + "6464646464646464…", expected.getMessage()); } }
@Override public int readUnsignedByte() throws IOException { if (this.position < this.end) { return (this.buffer[this.position++] & 0xff); } else { throw new EOFException(); } }
private void skipFully (int count) throws IOException { while (count > 0) { long skipped = in.skip(count); if (skipped <= 0) throw new EOFException("Unable to skip."); count -= skipped; } }
@Test public void readUtf8LineStrictNoBytesConsumedOnFailure() throws IOException { data.writeUtf8("abc\n"); try { source.readUtf8LineStrict(2); fail(); } catch (EOFException expected) { assertTrue(expected.getMessage().startsWith("\\n not found: limit=2 content=61626")); } assertEquals("abc", source.readUtf8LineStrict(3)); }
/** * Reads a byte from the input stream checking that the end of file (EOF) has not been * encountered. * * @return byte read from input * @throws IOException if an error is encountered while reading * @throws EOFException if the end of file (EOF) is encountered. */ private byte readAndCheckByte() throws IOException, EOFException { int b1 = in.read(); if (-1 == b1) { throw new EOFException(); } return (byte) b1; } }
@Override public void skipBytesToWrite(int numBytes) throws IOException { if (buffer.length - this.position < numBytes){ throw new EOFException("Could not skip " + numBytes + " bytes."); } this.position += numBytes; }
private void skipFully (int count) throws IOException { while (count > 0) { long skipped = in.skip(count); if (skipped <= 0) throw new EOFException("Unable to skip."); count -= skipped; } }
@Test public void readLines() throws IOException { data.writeUtf8("abc\ndef\n"); assertEquals("abc", source.readUtf8LineStrict()); assertEquals("def", source.readUtf8LineStrict()); try { source.readUtf8LineStrict(); fail(); } catch (EOFException expected) { assertEquals("\\n not found: limit=0 content=…", expected.getMessage()); } }
public void readFully (byte[] b, int off, int len) throws IOException { while (len > 0) { int count = is.read(b, off, len); if (count <= 0) { throw new EOFException(); } off += count; len -= count; } }
@Override public char readChar() throws IOException { if (this.position < this.end - 1) { return (char) (((this.memory[this.position++] & 0xff) << 8) | ((this.memory[this.position++] & 0xff) << 0)); } else { throw new EOFException(); } }
private void skipFully (int count) throws IOException { while (count > 0) { long skipped = in.skip(count); if (skipped <= 0) throw new EOFException("Unable to skip."); count -= skipped; } }
private int read() throws IOException { int v = is.read(); if (v != -1) { readBytes++; return v; } else { throw new EOFException(); } }
@Override public short readShort() throws IOException { if (position >= 0 && position < this.end - 1) { return (short) ((((this.memory[position++]) & 0xff) << 8) | (((this.memory[position++]) & 0xff) << 0)); } else { throw new EOFException(); } }
@Override public void seek(long desired) throws IOException { if (desired < this.pos) { throw new IllegalArgumentException("Wrapped InputStream: cannot search backwards."); } while (this.pos < desired) { long numReadBytes = this.inStream.skip(desired - pos); if (numReadBytes == -1) { throw new EOFException("Unexpected EOF during forward seek."); } this.pos += numReadBytes; } }
/** * Reads the next byte from the input stream. * @param input the stream * @return the byte * @throws IOException if the end of file is reached */ private static int read(final InputStream input) throws IOException { final int value = input.read(); if( EOF == value ) { throw new EOFException( "Unexpected EOF reached" ); } return value; } }
@Override public boolean readBoolean() throws IOException { if (this.position < this.end) { return this.buffer[this.position++] != 0; } else { throw new EOFException(); } }
public final void skip(int bytes) throws IOException { if (bytes<=0) { return; } long skipped=m_stream.skip(bytes); m_position+=skipped; if (skipped!=bytes) { throw new EOFException(); } }