/** * Creates a new RAES read-only channel. * * @param param the {@link RaesParameters} required to access the RAES * type actually found in the file. * If the class of this parameter does not match the required * parameter interface according to the RAES type found in the * file, but is an instance of the {@link RaesParametersProvider} * interface, then it gets queried to find the required RAES * parameters. * This algorithm gets recursively applied. * @param channel the channel for reading the RAES file from. * @return A new RAES read-only channel. * @throws RaesParametersException If no RAES parameter can be found which * match the type of RAES file in the given channel. * @throws RaesException If the source data is not RAES compatible. * @throws EOFException on unexpected end-of-file. * @throws IOException on any I/O error. */ @CreatesObligation private static RaesReadOnlyChannel create( final RaesParameters param, final @WillCloseWhenClosed SeekableByteChannel channel) throws RaesParametersException, RaesException, EOFException, IOException { final PowerBuffer header = PowerBuffer .allocate(HEADER_MIN_LEN) .littleEndian() .load(channel.position(0)); if (SIGNATURE != header.getUInt()) throw new RaesException("No RAES signature!"); final int type = header.getUByte(); switch (type) { case 0: return new Type0RaesReadOnlyChannel( parameters(Type0RaesParameters.class, param), channel); default: throw new RaesException("Unknown RAES type: " + type); } }
/** * Constructs {@link CSVReader} with supplied {@link CSVParser}. * * @param aReader * the reader to an underlying CSV source. * @param aParser * the parser to use to parse input * @param bKeepCR * <code>true</code> to keep carriage returns in data read, * <code>false</code> otherwise */ public CSVReader (@Nonnull @WillCloseWhenClosed final Reader aReader, @Nonnull final CSVParser aParser, final boolean bKeepCR) { ValueEnforcer.notNull (aReader, "Reader"); ValueEnforcer.notNull (aParser, "Parser"); Reader aInternallyBufferedReader = StreamHelper.getBuffered (aReader); if (bKeepCR) m_aLineReader = new CSVLineReaderKeepCR (aInternallyBufferedReader); else { if (!(aInternallyBufferedReader instanceof NonBlockingBufferedReader)) { // It is buffered, but we need it to support readLine aInternallyBufferedReader = new NonBlockingBufferedReader (aInternallyBufferedReader); } m_aLineReader = new CSVLineReaderNonBlockingBufferedReader ((NonBlockingBufferedReader) aInternallyBufferedReader); } m_aReader = aInternallyBufferedReader; m_aParser = aParser; m_bKeepCR = bKeepCR; }
@CreatesObligation public ThrowingInputStream( final @WillCloseWhenClosed InputStream in, final @CheckForNull FsThrowManager control) { super(in); this.control = null != control ? control : FsTestConfig.get().getThrowControl(); }
@CreatesObligation public ThrowingSeekableChannel( final @WillCloseWhenClosed SeekableByteChannel channel, final @CheckForNull FsThrowManager control) { super(channel); this.control = null != control ? control : FsTestConfig.get().getThrowControl(); }
@CreatesObligation public ThrowingOutputStream(final @WillCloseWhenClosed OutputStream out, final @CheckForNull FsThrowManager control) { super(out); this.control = null != control ? control : FsTestConfig.get().getThrowControl(); }
/** * Constructs a new multiplexed output service. * * @param output the decorated output service. * @param pool the pool for buffering entry data. */ public MultiplexingOutputService( final IoBufferPool pool, final @WillCloseWhenClosed OutputService<E> output) { super(output); this.pool = Objects.requireNonNull(pool); }
/** * Constructs a new cipher read-only channel. * * @param cipher the initialized, seekable block cipher. * @param channel the seekable byte channel. */ @CreatesObligation public CipherReadOnlyChannel( final SeekableBlockCipher cipher, final @WillCloseWhenClosed SeekableByteChannel channel) { this(cipher, channel, Streams.BUFFER_SIZE); }
/** * Constructs a new cipher read-only channel. * * @param cipher the seekable block cipher. * @param channel the seekable byte channel. * @param bufferSize the size of the byte buffer. * The value gets rounded down to a multiple of the cipher's * blocksize or the cipher's blocksize, whatever is larger. */ @CreatesObligation public CipherReadOnlyChannel( final SeekableBlockCipher cipher, final @WillCloseWhenClosed SeekableByteChannel channel, int bufferSize) { super(Objects.requireNonNull(channel)); this.cipher = Objects.requireNonNull(cipher); final int blockSize = cipher.getBlockSize(); block = new byte[blockSize]; if (bufferSize < blockSize) bufferSize = blockSize; buffer = new byte[bufferSize / blockSize * blockSize]; // round down to multiple of block size assert buffer.length % blockSize == 0; }
/** * Creates a new cipher output stream. * * @param cipher the block cipher. * @param out the output stream. */ @CreatesObligation public CipherOutputStream( final BufferedBlockCipher cipher, final @WillCloseWhenClosed OutputStream out) { super(Objects.requireNonNull(out)); this.cipher = Objects.requireNonNull(cipher); }
@CreatesObligation SafeBufferedReadOnlyChannel( final @WillCloseWhenClosed SeekableByteChannel channel, final long size) { super(channel); this.size = size; }
/** * Creates new helper for writing webfiles to a new zip archive. * * @param channel Java 7 byte {@code channel} already opened with write permission * @param compressionLevel {@link Deflater} compression level [1,9] which trades trade and size */ public WebfilesWriter(@WillCloseWhenClosed SeekableByteChannel channel, int compressionLevel) { this.channel = channel; buffer = new BufferedOutputStream(Channels.newOutputStream(channel), WebfilesUtils.BUFFER_SIZE); zip = new ZipOutputStream(buffer); // goes very slow without BufferedOutputStream zip.setComment("Created by Bazel Closure Rules"); zip.setLevel(compressionLevel); }
static AutoCloseableHtmlStreamRenderer createAutoCloseableHtmlStreamRenderer( @WillCloseWhenClosed Appendable output, Handler<? super IOException> errorHandler, Handler<? super String> badHtmlHandler) { return new AutoCloseableHtmlStreamRenderer( output, errorHandler, badHtmlHandler); }
private AutoCloseableHtmlStreamRenderer( @WillCloseWhenClosed Appendable output, Handler<? super IOException> errorHandler, Handler<? super String> badHtmlHandler) { super(output, errorHandler, badHtmlHandler); this.closeable = output; }
/** * Factory. * @param output the buffer to which HTML is streamed. * @param ioExHandler called with any exception raised by output. * @param badHtmlHandler receives alerts when HTML cannot be rendered because * there is not valid HTML tree that results from that series of calls. * E.g. it is not possible to create an HTML {@code <style>} element whose * textual content is {@code "</style>"}. */ public static HtmlStreamRenderer create( @WillCloseWhenClosed Appendable output, Handler<? super IOException> ioExHandler, Handler<? super String> badHtmlHandler) { if (output instanceof Closeable) { return new CloseableHtmlStreamRenderer( output, ioExHandler, badHtmlHandler); } else if (AutoCloseableHtmlStreamRenderer.isAutoCloseable(output)) { return AutoCloseableHtmlStreamRenderer.createAutoCloseableHtmlStreamRenderer( output, ioExHandler, badHtmlHandler); } else { return new HtmlStreamRenderer(output, ioExHandler, badHtmlHandler); } }
CloseableHtmlStreamRenderer( @WillCloseWhenClosed Appendable output, Handler<? super IOException> errorHandler, Handler<? super String> badHtmlHandler) { super(output, errorHandler, badHtmlHandler); this.closeable = (Closeable) output; }
/** * Auto-detect whether a stream needs decompression. Currently detects GZIP compression (using * the GZIP magic in the header). * * @param stream The stream to read. * @return A stream that will read from {@code stream}, decompressing if needed. It may not be * the same object as {@code stream}, even if no decompression is needed, as the input * stream may be wrapped in a buffered stream for lookahead. */ public static InputStream transparentlyDecompress(@WillCloseWhenClosed InputStream stream) throws IOException { InputStream buffered; // get a markable stream if (stream.markSupported()) { buffered = stream; } else { logger.debug("stream {} does not support mark, wrapping", stream); buffered = new BufferedInputStream(stream); } // read the first 2 bytes for GZIP magic buffered.mark(2); int b1 = buffered.read(); if (b1 < 0) { buffered.reset(); return buffered; } int b2 = buffered.read(); if (b2 < 0) { buffered.reset(); return buffered; } buffered.reset(); // they're in little-endian order int magic = b1 | (b2 << 8); logger.debug(String.format("found magic %x", magic)); if (magic == GZIPInputStream.GZIP_MAGIC) { logger.debug("stream is gzip-compressed, decompressing"); return new GZIPInputStream(buffered); } return buffered; }
@Nonnull public static SafeXMLStreamWriter create (@Nonnull @WillCloseWhenClosed final OutputStream aOS, @Nonnull final IXMLWriterSettings aSettings) { ValueEnforcer.notNull (aOS, "OutputStream"); return create (new OutputStreamWriter (aOS, aSettings.getCharset ()), aSettings); }
public MMapStringValueLookup(@WillCloseWhenClosed final BufferResource docIdToAddressBuffer, @WillCloseWhenClosed final BufferResource stringValuesBuffer) { this.docIdToAddressBuffer = docIdToAddressBuffer; this.stringValuesBuffer = stringValuesBuffer; docIdToAddress = docIdToAddressBuffer.memory(); stringValues = stringValuesBuffer.memory(); }
public ThrowingOutputService( final @WillCloseWhenClosed OutputService<E> service) { this(service, null); }
public ThrowingOutputService( final @WillCloseWhenClosed OutputService<E> service, final @CheckForNull FsTestConfig config) { super(service); this.config = null != config ? config : FsTestConfig.get(); }
public ThrowingInputService( final @WillCloseWhenClosed InputService<E> service) { this(service, null); }
public ThrowingInputService( final @WillCloseWhenClosed InputService<E> service, final @CheckForNull FsTestConfig config) { super(service); this.config = null != config ? config : FsTestConfig.get(); }
@CreatesObligation public ThrowingInputStream(@WillCloseWhenClosed InputStream in) { this(in, null); }
@CreatesObligation public ThrowingSeekableChannel( @WillCloseWhenClosed SeekableByteChannel sbc) { this(sbc, null); }
@CreatesObligation public ThrowingOutputStream(@WillCloseWhenClosed OutputStream out) { this(out, null); }
EntryOutputStream(final @WillCloseWhenClosed OutputStream out) { super(out); busy = true; }
@CreatesObligation DummyByteChannelInputStream( @WillCloseWhenClosed SeekableByteChannel channel) { super(channel); }
@CreatesObligation ZipInflaterInputStream(@WillCloseWhenClosed InputStream in, int size) { super(in, new Inflater(true), size); }
AppendingLittleEndianOutputStream( final @WillCloseWhenClosed OutputStream out, final @WillNotClose AbstractZipFile<?> appendee) { super(out); super.written = appendee.getOffsetMapper().unmap(appendee.length()); }
@CreatesObligation CountingInputStream(@WillCloseWhenClosed InputStream in) { super(in); }
HasherInputStream(@WillCloseWhenClosed InputStream delegate, Hasher hasher) { this.delegate = delegate; this.hasher = hasher; }
Input(@WillCloseWhenClosed InputStream input, String name, DateTime modified) { super(input); this.name = checkNotNull(name, "name"); this.modified = checkNotNull(modified, "modified"); }
Output(@WillCloseWhenClosed OutputStream os) { super(os); }
Encryptor(@WillCloseWhenClosed OutputStream os) { super(os); }
Decryptor(@WillCloseWhenClosed InputStream input, PGPPublicKeyEncryptedData crypt) { super(input); this.crypt = checkNotNull(crypt, "crypt"); }
Compressor(@WillCloseWhenClosed OutputStream os) { super(os); }
Decompressor(@WillCloseWhenClosed InputStream input) { super(input); }
public ImprovedOutputStream(@WillCloseWhenClosed OutputStream out) { this(out, true, -1); }
public ImprovedInputStream(@WillCloseWhenClosed InputStream out) { this(out, true, -1); }
@Nonnull public static SafeXMLStreamWriter create (@Nonnull @WillCloseWhenClosed final Writer aWriter, @Nonnull final IXMLWriterSettings aSettings) { return new SafeXMLStreamWriter (new XMLEmitter (aWriter, aSettings)); }