/** Notifies the observers by invoking {@link Observer#finished()}. * @throws IOException Some observer has thrown an exception, which is being * passed down. */ protected void noteFinished() throws IOException { for (final Observer observer : getObservers()) { observer.finished(); } }
/** Notifies the observers by invoking {@link Observer#data(int)} * with the given arguments. * @param pDataByte Passed to the observers. * @throws IOException Some observer has thrown an exception, which is being * passed down. */ protected void noteDataByte(final int pDataByte) throws IOException { for (final Observer observer : getObservers()) { observer.data(pDataByte); } }
/** Notifies the observers by invoking {@link Observer#finished()}. * @throws IOException Some observer has thrown an exception, which is being * passed down. */ protected void noteClosed() throws IOException { for (final Observer observer : getObservers()) { observer.closed(); } }
/** * Indicates whether the stream contains one of the specified BOMs. * * @return true if the stream has one of the specified BOMs, otherwise false if it does not * @throws IOException * if an error reading the first bytes of the stream occurs */ public boolean hasBOM() throws IOException { return getBOM() != null; }
/** * Creates and starts a Tailer for the given file, starting at the beginning of the file * * @param file the file to follow. * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @return The new tailer */ public static Tailer create(final File file, final TailerListener listener, final long delayMillis) { return create(file, listener, delayMillis, false); }
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ @Override public void close() { in = new ClosedInputStream(); }
@Override public int read(final char[] chars) throws IOException { return chars == null ? 0 : super.read(chars); } @Override
/** * Return <code>{@link #readByte()} != 0</code> * @return false if the byte read is zero, otherwise true * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ @Override public boolean readBoolean() throws IOException, EOFException { return 0 != readByte(); }
@Test public void testNullCharArray() throws Exception { final ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0)); proxy.read((char[])null); proxy.read(null, 0, 0); proxy.close(); }
/** * Read the specified number of bytes into an array. * * @param b the byte array to read into * @return the number of bytes read or <code>-1</code> * if the end of the stream has been reached * @throws IOException if an I/O error occurs */ @Override public int read(final byte[] b) throws IOException { return read(b, 0, b.length); }
/** Creates a new instance, which calculates a signature on the given stream, * using the given {@link MessageDigest}. * @param pStream the stream to calculate the message digest for * @param pDigest the message digest to use */ public MessageDigestCalculatingInputStream(final InputStream pStream, final MessageDigest pDigest) { super(pStream); messageDigest = pDigest; add(new MessageDigestMaintainingObserver(pDigest)); }
/** Notifies the observers by invoking {@link Observer#error(IOException)} * with the given argument. * @param pException Passed to the observers. * @throws IOException Some observer has thrown an exception, which is being * passed down. This may be the same exception, which has been passed as an * argument. */ protected void noteError(final IOException pException) throws IOException { for (final Observer observer : getObservers()) { observer.error(pException); } }
protected String calculateRawEncoding(final String bomEnc, final String xmlGuessEnc, final String xmlEnc, final String defaultEncoding) throws IOException { final MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding); final String enc = mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc); mock.close(); return enc; }
@Override void data(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { super.data(pBuffer, pOffset, pLength); buffer = pBuffer; offset = pOffset; length = pLength; } }
@Override protected void processBytes(final byte[] bytes, final int offset, final int length) { final int startPos = (int)getPosition() - length; for (int i = offset; i < length; i++) { bytes[i] = (byte)(startPos + i); } }
@Override protected void processChars(final char[] chars, final int offset, final int length) { final int startPos = (int)getPosition() - length; for (int i = offset; i < length; i++) { chars[i] = (char)(startPos + i); } }
@Override public boolean equals(final Object other) { if (other instanceof Test) { final Test tother = (Test) other; return (this.i == tother.i) & (this.e == tother.e) & equalObject(tother.o); } else { return false; } }
@Override public int read(final CharBuffer target) throws IOException { return target == null ? 0 : super.read(target); } }
@Test public void testNullCharBuffer() throws Exception { final ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0)); proxy.read((CharBuffer)null); proxy.close(); }
/** Notifies the observers by invoking {@link Observer#data(byte[],int,int)} * with the given arguments. * @param pBuffer Passed to the observers. * @param pOffset Passed to the observers. * @param pLength Passed to the observers. * @throws IOException Some observer has thrown an exception, which is being * passed down. */ protected void noteDataBytes(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { for (final Observer observer : getObservers()) { observer.data(pBuffer, pOffset, pLength); } }