Java 类javax.annotation.WillCloseWhenClosed 实例源码

项目:truevfs    文件:RaesReadOnlyChannel.java   
/**
 * 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);
    }
}
项目:ph-commons    文件:CSVReader.java   
/**
 * 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;
}
项目:truevfs    文件:ThrowingInputStream.java   
@CreatesObligation
public ThrowingInputStream( final @WillCloseWhenClosed InputStream in,
                            final @CheckForNull FsThrowManager control) {
    super(in);
    this.control = null != control
            ? control
            : FsTestConfig.get().getThrowControl();
}
项目:truevfs    文件:ThrowingSeekableChannel.java   
@CreatesObligation
public ThrowingSeekableChannel(
        final @WillCloseWhenClosed SeekableByteChannel channel,
        final @CheckForNull FsThrowManager control) {
    super(channel);
    this.control = null != control
            ? control
            : FsTestConfig.get().getThrowControl();
}
项目:truevfs    文件:ThrowingOutputStream.java   
@CreatesObligation
public ThrowingOutputStream(final @WillCloseWhenClosed OutputStream out,
                            final @CheckForNull FsThrowManager control) {
    super(out);
    this.control = null != control
            ? control
            : FsTestConfig.get().getThrowControl();
}
项目:truevfs    文件:MultiplexingOutputService.java   
/**
 * 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);
}
项目:truevfs    文件:CipherReadOnlyChannel.java   
/**
 * 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);
}
项目:truevfs    文件:CipherReadOnlyChannel.java   
/**
 * 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;
}
项目:truevfs    文件:CipherOutputStream.java   
/**
 * 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);
}
项目:truevfs    文件:AbstractZipFile.java   
@CreatesObligation
SafeBufferedReadOnlyChannel(
        final @WillCloseWhenClosed SeekableByteChannel channel,
        final long size) {
    super(channel);
    this.size = size;
}
项目:rules_closure    文件:WebfilesWriter.java   
/**
 * 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);
}
项目:java-html-sanitizer    文件:AutoCloseableHtmlStreamRenderer.java   
static AutoCloseableHtmlStreamRenderer createAutoCloseableHtmlStreamRenderer(
    @WillCloseWhenClosed
    Appendable output, Handler<? super IOException> errorHandler,
    Handler<? super String> badHtmlHandler) {
  return new AutoCloseableHtmlStreamRenderer(
      output, errorHandler, badHtmlHandler);
}
项目:java-html-sanitizer    文件:AutoCloseableHtmlStreamRenderer.java   
private AutoCloseableHtmlStreamRenderer(
    @WillCloseWhenClosed
    Appendable output, Handler<? super IOException> errorHandler,
    Handler<? super String> badHtmlHandler) {
  super(output, errorHandler, badHtmlHandler);
  this.closeable = output;
}
项目:java-html-sanitizer    文件:HtmlStreamRenderer.java   
/**
 * 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);
  }
}
项目:java-html-sanitizer    文件:HtmlStreamRenderer.java   
CloseableHtmlStreamRenderer(
    @WillCloseWhenClosed
    Appendable output, Handler<? super IOException> errorHandler,
    Handler<? super String> badHtmlHandler) {
  super(output, errorHandler, badHtmlHandler);
  this.closeable = (Closeable) output;
}
项目:C1_ParknShop    文件:LKFileUtils.java   
/**
 * 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;
}
项目:ph-commons    文件:SafeXMLStreamWriter.java   
@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);
}
项目:imhotep    文件:MMapStringValueLookup.java   
public MMapStringValueLookup(@WillCloseWhenClosed final BufferResource docIdToAddressBuffer,
                             @WillCloseWhenClosed final BufferResource stringValuesBuffer) {
    this.docIdToAddressBuffer = docIdToAddressBuffer;
    this.stringValuesBuffer = stringValuesBuffer;
    docIdToAddress = docIdToAddressBuffer.memory();
    stringValues = stringValuesBuffer.memory();
}
项目:truevfs    文件:ThrowingOutputService.java   
public ThrowingOutputService(
        final @WillCloseWhenClosed OutputService<E> service) {
    this(service, null);
}
项目:truevfs    文件:ThrowingOutputService.java   
public ThrowingOutputService(
        final @WillCloseWhenClosed OutputService<E> service,
        final @CheckForNull FsTestConfig config) {
    super(service);
    this.config = null != config ? config : FsTestConfig.get();
}
项目:truevfs    文件:ThrowingInputService.java   
public ThrowingInputService(
        final @WillCloseWhenClosed InputService<E> service) {
    this(service, null);
}
项目:truevfs    文件:ThrowingInputService.java   
public ThrowingInputService(
        final @WillCloseWhenClosed InputService<E> service,
        final @CheckForNull FsTestConfig config) {
    super(service);
    this.config = null != config ? config : FsTestConfig.get();
}
项目:truevfs    文件:ThrowingInputStream.java   
@CreatesObligation
public ThrowingInputStream(@WillCloseWhenClosed InputStream in) {
    this(in, null);
}
项目:truevfs    文件:ThrowingSeekableChannel.java   
@CreatesObligation
public ThrowingSeekableChannel(
        @WillCloseWhenClosed SeekableByteChannel sbc) {
    this(sbc, null);
}
项目:truevfs    文件:ThrowingOutputStream.java   
@CreatesObligation
public ThrowingOutputStream(@WillCloseWhenClosed OutputStream out) {
    this(out, null);
}
项目:truevfs    文件:MultiplexingOutputService.java   
EntryOutputStream(final @WillCloseWhenClosed OutputStream out) {
    super(out);
    busy = true;
}
项目:truevfs    文件:DummyByteChannelInputStream.java   
@CreatesObligation
DummyByteChannelInputStream(
        @WillCloseWhenClosed SeekableByteChannel channel) {
    super(channel);
}
项目:truevfs    文件:ZipInflaterInputStream.java   
@CreatesObligation
ZipInflaterInputStream(@WillCloseWhenClosed InputStream in, int size) {
    super(in, new Inflater(true), size);
}
项目:truevfs    文件:AbstractZipOutputStream.java   
AppendingLittleEndianOutputStream(
        final @WillCloseWhenClosed OutputStream out,
        final @WillNotClose AbstractZipFile<?> appendee) {
    super(out);
    super.written = appendee.getOffsetMapper().unmap(appendee.length());
}
项目:truevfs    文件:CountingInputStream.java   
@CreatesObligation
CountingInputStream(@WillCloseWhenClosed InputStream in) {
    super(in);
}
项目:rules_closure    文件:HasherInputStream.java   
HasherInputStream(@WillCloseWhenClosed InputStream delegate, Hasher hasher) {
  this.delegate = delegate;
  this.hasher = hasher;
}
项目:nomulus    文件:Ghostryde.java   
Input(@WillCloseWhenClosed InputStream input, String name, DateTime modified) {
  super(input);
  this.name = checkNotNull(name, "name");
  this.modified = checkNotNull(modified, "modified");
}
项目:nomulus    文件:Ghostryde.java   
Output(@WillCloseWhenClosed OutputStream os) {
  super(os);
}
项目:nomulus    文件:Ghostryde.java   
Encryptor(@WillCloseWhenClosed OutputStream os) {
  super(os);
}
项目:nomulus    文件:Ghostryde.java   
Decryptor(@WillCloseWhenClosed InputStream input, PGPPublicKeyEncryptedData crypt) {
  super(input);
  this.crypt = checkNotNull(crypt, "crypt");
}
项目:nomulus    文件:Ghostryde.java   
Compressor(@WillCloseWhenClosed OutputStream os) {
  super(os);
}
项目:nomulus    文件:Ghostryde.java   
Decompressor(@WillCloseWhenClosed InputStream input) {
  super(input);
}
项目:nomulus    文件:ImprovedOutputStream.java   
public ImprovedOutputStream(@WillCloseWhenClosed OutputStream out) {
  this(out, true, -1);
}
项目:nomulus    文件:ImprovedInputStream.java   
public ImprovedInputStream(@WillCloseWhenClosed InputStream out) {
  this(out, true, -1);
}
项目:ph-commons    文件:SafeXMLStreamWriter.java   
@Nonnull
public static SafeXMLStreamWriter create (@Nonnull @WillCloseWhenClosed final Writer aWriter,
                                          @Nonnull final IXMLWriterSettings aSettings)
{
  return new SafeXMLStreamWriter (new XMLEmitter (aWriter, aSettings));
}