java类javax.annotation.WillNotClose的实例源码

TarInputService.java 文件源码 项目:truevfs 阅读 59 收藏 0 点赞 0 评论 0
/**
 * Fills {@code buf} with data from the given input stream and
 * returns an input stream from which you can still read all data,
 * including the data in buf.
 *
 * @param  in The stream to read from.
 * @param  buf The buffer to fill entirely with data.
 * @return A stream which holds all the data {@code in} did.
 * @throws EOFException on unexpected end-of-file.
 * @throws IOException on any I/O error.
 */
private static InputStream readAhead(
        final @WillNotClose InputStream in,
        final byte[] buf)
throws EOFException, IOException {
    if (in.markSupported()) {
        in.mark(buf.length);
        new DataInputStream(in).readFully(buf);
        in.reset();
        return in;
    } else {
        final PushbackInputStream
                pin = new PushbackInputStream(in, buf.length);
        new DataInputStream(pin).readFully(buf);
        pin.unread(buf);
        return pin;
    }
}
AbstractArtifactMojo.java 文件源码 项目:minecraft-maven-plugin 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Fetches any resource from a remote HTTP server and writes it to a supplied channel.
 */
protected void fetch(@Nonnull URI uri, @Nonnull @WillNotClose WritableByteChannel outputChannel) throws IOException {
    HttpClient client = HttpClients.createMinimal();

    HttpGet request = new HttpGet(uri);
    HttpResponse response = client.execute(request);

    StatusLine line = response.getStatusLine();

    if (line.getStatusCode() != 200) {
        throw new IOException("Unexpected status code: " + line.getStatusCode() + " - " + line.getReasonPhrase());
    }

    try (InputStream inputStream = response.getEntity().getContent()) {
        try (ReadableByteChannel inputChannel = Channels.newChannel(inputStream)) {
            ByteStreams.copy(inputChannel, outputChannel);
        }
    }
}
Ghostryde.java 文件源码 项目:nomulus 阅读 36 收藏 0 点赞 0 评论 0
/**
 * Opens a new {@link Decryptor} (Reading Step 1/3)
 *
 * <p>This is the first step in opening a ghostryde file. After this method, you'll want to
 * call {@link #openDecompressor(Decryptor)}.
 *
 * @param input is an {@link InputStream} of the ghostryde file data.
 * @param privateKey is the private encryption key of the recipient (which is us!)
 * @throws IOException
 * @throws PGPException
 */
@CheckReturnValue
public Decryptor openDecryptor(@WillNotClose InputStream input, PGPPrivateKey privateKey)
    throws IOException, PGPException {
  checkNotNull(privateKey, "privateKey");
  PGPObjectFactory fact = new BcPGPObjectFactory(checkNotNull(input, "input"));
  PGPEncryptedDataList crypts = pgpCast(fact.nextObject(), PGPEncryptedDataList.class);
  checkState(crypts.size() > 0);
  if (crypts.size() > 1) {
    logger.warningfmt("crypts.size() is %d (should be 1)", crypts.size());
  }
  PGPPublicKeyEncryptedData crypt = pgpCast(crypts.get(0), PGPPublicKeyEncryptedData.class);
  if (crypt.getKeyID() != privateKey.getKeyID()) {
    throw new PGPException(String.format(
        "Message was encrypted for keyid %x but ours is %x",
        crypt.getKeyID(), privateKey.getKeyID()));
  }
  return new Decryptor(
      crypt.getDataStream(new BcPublicKeyDataDecryptorFactory(privateKey)),
      crypt);
}
RydeTarOutputStream.java 文件源码 项目:nomulus 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Creates a new instance that outputs a tar archive.
 *
 * @param os is the upstream {@link OutputStream} which is not closed by this object
 * @param size is the length in bytes of the one file, which you will write to this object
 * @param modified is the {@link PosixTarHeader.Builder#setMtime mtime} you want to set
 * @param filename is the name of the one file that will be contained in this archive
 * @throws RuntimeException to rethrow {@link IOException}
 * @throws IllegalArgumentException if {@code size} is negative
 */
public RydeTarOutputStream(
    @WillNotClose OutputStream os, long size, DateTime modified, String filename) {
  super(os, false, size);
  checkArgument(size >= 0);
  checkArgument(filename.endsWith(".xml"),
      "Ryde expects tar archive to contain a filename with an '.xml' extension.");
  try {
    os.write(new PosixTarHeader.Builder()
        .setName(filename)
        .setSize(size)
        .setMtime(modified)
        .build()
        .getBytes());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
LZFSELiteralDecoder.java 文件源码 项目:InflatableDonkey 阅读 36 收藏 0 点赞 0 评论 0
@Nonnull
LZFSELiteralDecoder decodeInto(@WillNotClose ReadableByteChannel ch, byte[] literals)
        throws IOException, LZFSEDecoderException {
    initBuffer();
    IO.readFully(ch, bb);
    BitInStream in = new BitInStream(bb)
            .init(literalBits);

    for (int i = 0; i < nLiterals; i += 4) {
        in.fill();
        literals[i + 0] = tans.transition(state0, in).symbol();
        literals[i + 1] = tans.transition(state1, in).symbol();
        literals[i + 2] = tans.transition(state2, in).symbol();
        literals[i + 3] = tans.transition(state3, in).symbol();
    }
    return this;
}
SimpleJDBCRecordStore.java 文件源码 项目:jactiverecord 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Helper method to support large queries not supported by the underlying JDBC driver
 * @param query the query to check and potentially convert
 * @param cond the condition to extract the wildcards from
 * @return the resulting ResultSet
 * @throws SQLException
 */
@Nonnull
@WillNotClose
protected ResultSet queryStatement(@Nonnull final String query, @Nullable final Condition cond) throws SQLException
{
    if(cond != null && cond.hasWildcards())
    {
        if(cond.getValues().length > driver.getParametersLimit())
        {
            final String preparedQuery = StatementUtil.prepareQuery(driver, query, cond );
            return diagnostics.profileQuery( () -> closeStatementWithResultSet( con.createStatement( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)).executeQuery( preparedQuery ), () -> preparedQuery).get();
        }
    }
    final PreparedStatement stm = closeStatementWithResultSet( con.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
    if(cond != null)
    {
        fillStatement( stm, cond );
    }
    return diagnostics.profileQuery(() -> stm.executeQuery(), () -> StatementUtil.prepareQuery(driver, query, cond )).get();
}
SimpleJDBCRecordStore.java 文件源码 项目:jactiverecord 阅读 32 收藏 0 点赞 0 评论 0
@Override
@WillNotClose
public Stream<Object> getValues( final String tableName, final String column, final String condColumn, final Object condValue ) throws
IllegalArgumentException
{
    //FIXME ResultSet is never closed if Stream is not read to the end!! (in all methods returning a Stream)
    final String sql = "SELECT "+column+" FROM " +tableName+ " WHERE "+condColumn+" = ?";
    Logging.getLogger().debug( "JDBCStore", sql);
    try
    {
        //can't use try-with-resource here, because result-set is required to stay open
        final ResultSet res = queryStatement( sql, Conditions.is( condColumn, condValue));
        return valuesStream(res);
    }
    catch ( final SQLException ex )
    {
        Logging.getLogger().error( "JDBCStore", "Failed to retrieve values!");
        Logging.getLogger().error( "JDBCStore", sql);
        Logging.getLogger().error( "JDBCStore", ex);
        throw new IllegalArgumentException(ex);
    }
}
QuotedPrintableCodec.java 文件源码 项目:ph-commons 阅读 23 收藏 0 点赞 0 评论 0
public void encode (@Nullable final byte [] aDecodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aDecodedBuffer == null || nLen == 0)
    return;

  try
  {
    for (int i = 0; i < nLen; ++i)
    {
      final int b = aDecodedBuffer[nOfs + i] & 0xff;
      if (m_aPrintableChars.get (b))
        aOS.write (b);
      else
        writeEncodeQuotedPrintableByte (b, aOS);
    }
  }
  catch (final IOException ex)
  {
    throw new EncodeException ("Failed to encode quoted-printable", ex);
  }
}
Base16Codec.java 文件源码 项目:ph-commons 阅读 95 收藏 0 点赞 0 评论 0
public void encode (@Nonnull @WillNotClose final InputStream aDecodedIS,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  ValueEnforcer.notNull (aDecodedIS, "DecodedInputStream");
  ValueEnforcer.notNull (aOS, "OutputStream");

  try
  {
    int nByte;
    while ((nByte = aDecodedIS.read ()) != -1)
    {
      aOS.write (StringHelper.getHexChar ((nByte & 0xf0) >> 4));
      aOS.write (StringHelper.getHexChar (nByte & 0x0f));
    }
  }
  catch (final IOException ex)
  {
    throw new EncodeException ("Failed to encode Base16", ex);
  }
}
GZIPCodec.java 文件源码 项目:ph-commons 阅读 29 收藏 0 点赞 0 评论 0
public void decode (@Nullable final byte [] aEncodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aEncodedBuffer == null || nLen == 0)
    return;

  try (final GZIPInputStream aDecodeIS = new GZIPInputStream (new NonBlockingByteArrayInputStream (aEncodedBuffer,
                                                                                                   nOfs,
                                                                                                   nLen)))
  {
    if (StreamHelper.copyInputStreamToOutputStream (aDecodeIS, aOS).isFailure ())
      throw new DecodeException ("Failed to GZIP decode!");
  }
  catch (final IOException ex)
  {
    throw new DecodeException ("Failed to GZIP encode", ex);
  }
}
GZIPCodec.java 文件源码 项目:ph-commons 阅读 27 收藏 0 点赞 0 评论 0
public void encode (@Nullable final byte [] aDecodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aDecodedBuffer == null || nLen == 0)
    return;

  try (final GZIPOutputStream aEncodeOS = new GZIPOutputStream (new NonClosingOutputStream (aOS)))
  {
    if (StreamHelper.copyInputStreamToOutputStream (new NonBlockingByteArrayInputStream (aDecodedBuffer, nOfs, nLen),
                                                    aEncodeOS)
                    .isFailure ())
      throw new EncodeException ("Failed to GZIP encode!");
  }
  catch (final IOException ex)
  {
    throw new EncodeException ("Failed to GZIP encode", ex);
  }
}
FlateCodec.java 文件源码 项目:ph-commons 阅读 24 收藏 0 点赞 0 评论 0
public void decode (@Nullable final byte [] aEncodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aEncodedBuffer == null || nLen == 0)
    return;

  if (!isZlibHead (aEncodedBuffer, nOfs, nLen))
    s_aLogger.warn ("ZLib header not found");

  try (final InflaterInputStream aDecodeIS = new InflaterInputStream (new NonBlockingByteArrayInputStream (aEncodedBuffer,
                                                                                                           nOfs,
                                                                                                           nLen)))
  {
    if (StreamHelper.copyInputStreamToOutputStream (aDecodeIS, aOS).isFailure ())
      throw new DecodeException ("Failed to flate decode!");
  }
  catch (final IOException ex)
  {
    throw new DecodeException ("Failed to flate encode", ex);
  }
}
FlateCodec.java 文件源码 项目:ph-commons 阅读 30 收藏 0 点赞 0 评论 0
public void encode (@Nullable final byte [] aDecodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aDecodedBuffer == null || nLen == 0)
    return;

  try (final DeflaterOutputStream aEncodeOS = new DeflaterOutputStream (new NonClosingOutputStream (aOS)))
  {
    if (StreamHelper.copyInputStreamToOutputStream (new NonBlockingByteArrayInputStream (aDecodedBuffer, nOfs, nLen),
                                                    aEncodeOS)
                    .isFailure ())
      throw new EncodeException ("Failed to flate encode!");
  }
  catch (final IOException ex)
  {
    throw new EncodeException ("Failed to flate encode", ex);
  }
}
Base64Codec.java 文件源码 项目:ph-commons 阅读 31 收藏 0 点赞 0 评论 0
public void encode (@Nullable final byte [] aDecodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aDecodedBuffer == null || nLen == 0)
    return;

  try (final Base64OutputStream aB64OS = new Base64OutputStream (new NonClosingOutputStream (aOS)))
  {
    aB64OS.write (aDecodedBuffer, nOfs, nLen);
  }
  catch (final IOException ex)
  {
    throw new EncodeException ("Failed to encode Base64", ex);
  }
}
Base64Codec.java 文件源码 项目:ph-commons 阅读 31 收藏 0 点赞 0 评论 0
public void decode (@Nullable final byte [] aEncodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  try (final Base64InputStream aB64OS = new Base64InputStream (new NonBlockingByteArrayInputStream (aEncodedBuffer,
                                                                                                    nOfs,
                                                                                                    nLen)))
  {
    if (StreamHelper.copyInputStreamToOutputStream (aB64OS, aOS).isFailure ())
      throw new DecodeException ("Failed to decode Base64!");
  }
  catch (final IOException ex)
  {
    throw new DecodeException ("Failed to decode Base64!", ex);
  }
}
NonBlockingByteArrayOutputStream.java 文件源码 项目:ph-commons 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Reads the given {@link InputStream} completely into the buffer.
 *
 * @param aIS
 *        the InputStream to read from. May not be <code>null</code>. Is not
 *        closed internally.
 * @throws IOException
 *         If reading fails
 */
public void readFrom (@Nonnull @WillNotClose final InputStream aIS) throws IOException
{
  while (true)
  {
    if (m_nCount == m_aBuf.length)
    {
      // reallocate
      m_aBuf = _enlarge (m_aBuf, m_aBuf.length << 1);
    }

    final int nBytesRead = aIS.read (m_aBuf, m_nCount, m_aBuf.length - m_nCount);
    if (nBytesRead < 0)
      return;
    m_nCount += nBytesRead;
  }
}
ChannelHelper.java 文件源码 项目:ph-commons 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Copy all content from the source channel to the destination channel.
 *
 * @param aSrc
 *        Source channel. May not be <code>null</code>. Is not closed after
 *        the operation.
 * @param aDest
 *        Destination channel. May not be <code>null</code>. Is not closed
 *        after the operation.
 * @return The number of bytes written.
 * @throws IOException
 *         In case of IO error
 */
@Nonnegative
public static long channelCopy (@Nonnull @WillNotClose final ReadableByteChannel aSrc,
                                @Nonnull @WillNotClose final WritableByteChannel aDest) throws IOException
{
  ValueEnforcer.notNull (aSrc, "SourceChannel");
  ValueEnforcer.isTrue (aSrc.isOpen (), "SourceChannel is not open!");
  ValueEnforcer.notNull (aDest, "DestinationChannel");
  ValueEnforcer.isTrue (aDest.isOpen (), "DestinationChannel is not open!");

  long nBytesWritten;
  if (USE_COPY_V1)
    nBytesWritten = _channelCopy1 (aSrc, aDest);
  else
    nBytesWritten = _channelCopy2 (aSrc, aDest);
  return nBytesWritten;
}
ChannelHelper.java 文件源码 项目:ph-commons 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Channel copy method 2. This method performs the same copy, but assures the
 * temporary buffer is empty before reading more data. This never requires
 * data copying but may result in more systems calls. No post-loop cleanup is
 * needed because the buffer will be empty when the loop is exited.<br>
 * Source: Java NIO, page 60
 *
 * @param aSrc
 *        Source channel. May not be <code>null</code>. Is not closed after
 *        the operation.
 * @param aDest
 *        Destination channel. May not be <code>null</code>. Is not closed
 *        after the operation.
 * @return The number of bytes written.
 */
private static long _channelCopy2 (@Nonnull @WillNotClose final ReadableByteChannel aSrc,
                                   @Nonnull @WillNotClose final WritableByteChannel aDest) throws IOException
{
  long nBytesWritten = 0;
  final ByteBuffer aBuffer = ByteBuffer.allocateDirect (16 * 1024);
  while (aSrc.read (aBuffer) != -1)
  {
    // Prepare the buffer to be drained
    aBuffer.flip ();

    // Make sure that the buffer was fully drained
    while (aBuffer.hasRemaining ())
      nBytesWritten += aDest.write (aBuffer);

    // Make the buffer empty, ready for filling
    aBuffer.clear ();
  }
  return nBytesWritten;
}
FileChannelHelper.java 文件源码 项目:ph-commons 阅读 31 收藏 0 点赞 0 评论 0
@Nullable
private static InputStream _getMappedInputStream (@Nonnull @WillNotClose final FileChannel aChannel,
                                                  @Nonnull final File aFile)
{
  try
  {
    final MappedByteBuffer aBuffer = aChannel.map (MapMode.READ_ONLY, 0, aChannel.size ());
    s_aLogger.info ("Created memory mapped input stream for " + aFile);
    return new ByteBufferInputStream (aBuffer);
  }
  catch (final IOException ex)
  {
    s_aLogger.warn ("Failed to create memory mapped input stream for " + aFile, ex);
    return null;
  }
}
FileChannelHelper.java 文件源码 项目:ph-commons 阅读 29 收藏 0 点赞 0 评论 0
@Nullable
private static OutputStream _getMappedOutputStream (@Nonnull @WillNotClose final FileChannel aChannel,
                                                    @Nonnull final File aFile)
{
  try
  {
    // Maximum is Integer.MAX_VALUE even if a long is taken!
    final MappedByteBuffer aBuffer = aChannel.map (MapMode.READ_WRITE, 0, Integer.MAX_VALUE);
    s_aLogger.info ("Created memory mapped output stream for " + aFile);
    return new ByteBufferOutputStream (aBuffer, false);
  }
  catch (final IOException ex)
  {
    s_aLogger.warn ("Failed to create memory mapped output stream for " + aFile, ex);
    return null;
  }
}
Util.java 文件源码 项目:findbugs-all-the-bugs 阅读 28 收藏 0 点赞 0 评论 0
public static String getXMLType(@WillNotClose InputStream in) throws IOException {
    if (!in.markSupported())
        throw new IllegalArgumentException("Input stream does not support mark");

    in.mark(5000);
    BufferedReader r = null;
    try {
        r = new BufferedReader(Util.getReader(in), 2000);

        String s;
        int count = 0;
        while (count < 4) {
            s = r.readLine();
            if (s == null)
                break;
            Matcher m = tag.matcher(s);
            if (m.find())
                return m.group(1);
        }
        throw new IOException("Didn't find xml tag");
    } finally {
        in.reset();
    }

}
IO.java 文件源码 项目:findbugs-all-the-bugs 阅读 31 收藏 0 点赞 0 评论 0
public static long copy(@WillNotClose InputStream in, @WillNotClose OutputStream out, long maxBytes)

    throws IOException {
        long total = 0;

        int sz = 0;

        byte buf[] = myByteBuf.get();

        while (maxBytes > 0 && (sz = in.read(buf, 0, (int) Math.min(maxBytes, buf.length))) > 0) {
            total += sz;
            maxBytes -= sz;
            out.write(buf, 0, sz);
        }

        return total;
    }
Util.java 文件源码 项目:FindBug-for-Domino-Designer 阅读 31 收藏 0 点赞 0 评论 0
public static String getXMLType(@WillNotClose InputStream in) throws IOException {
    if (!in.markSupported())
        throw new IllegalArgumentException("Input stream does not support mark");

    in.mark(5000);
    BufferedReader r = null;
    try {
        r = new BufferedReader(Util.getReader(in), 2000);

        String s;
        int count = 0;
        while (count < 4) {
            s = r.readLine();
            if (s == null)
                break;
            Matcher m = tag.matcher(s);
            if (m.find())
                return m.group(1);
        }
        throw new IOException("Didn't find xml tag");
    } finally {
        in.reset();
    }

}
IO.java 文件源码 项目:FindBug-for-Domino-Designer 阅读 34 收藏 0 点赞 0 评论 0
public static long copy(@WillNotClose InputStream in, @WillNotClose OutputStream out, long maxBytes)

    throws IOException {
        long total = 0;

        int sz = 0;

        byte buf[] = myByteBuf.get();

        while (maxBytes > 0 && (sz = in.read(buf, 0, (int) Math.min(maxBytes, buf.length))) > 0) {
            total += sz;
            maxBytes -= sz;
            out.write(buf, 0, sz);
        }

        return total;
    }
MockArchiveDriver.java 文件源码 项目:truevfs 阅读 33 收藏 0 点赞 0 评论 0
@Override
protected OutputService<MockArchiveDriverEntry> newOutput(
        final FsModel model,
        final FsOutputSocketSink sink,
        final @CheckForNull @WillNotClose InputService<MockArchiveDriverEntry> input)
throws IOException {
    final FsMountPoint mp = model.getMountPoint();
    final MockArchive n = MockArchive.create(config);
    MockArchive o = containers.get(mp);
    if (null == o)
        o = containers.putIfAbsent(mp, n);
    return new MultiplexingOutputService<>(getPool(),
            (null != o ? o : n).newOutputService());
}
ReadOnlySfxDriver.java 文件源码 项目:truevfs 阅读 26 收藏 0 点赞 0 评论 0
@Override
public final OutputService<ZipDriverEntry> newOutput(
        FsModel model,
        BitField<FsAccessOption> options,
        FsController controller,
        FsNodeName name,
        @CheckForNull @WillNotClose InputService<ZipDriverEntry> input)
throws IOException {
    throw new FsReadOnlyFileSystemException(model.getMountPoint());
}
ParanoidZipRaesDriver.java 文件源码 项目:truevfs 阅读 21 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 * <p>
 * The implementation in the class {@link ParanoidZipRaesDriver} returns a
 * new {@link ZipOutputService}.
 * This restricts the number of concurrent sink entry streams to one in
 * order to inhibit writing unencrypted temporary files for buffering the
 * written entries.
 */
@Override
protected final ZipOutputService<JarDriverEntry> newOutput(
        final FsModel model,
        final FsOutputSocketSink sink,
        final @CheckForNull @WillNotClose InputService<JarDriverEntry> input)
throws IOException {
    final ZipInputService<JarDriverEntry> zis = (ZipInputService<JarDriverEntry>) input;
    return new ZipOutputService<>(model, new RaesSocketSink(model, sink), zis, this);
}
ZipRaesDriver.java 文件源码 项目:truevfs 阅读 25 收藏 0 点赞 0 评论 0
@Override
protected OutputService<JarDriverEntry> newOutput(
        final FsModel model,
        final FsOutputSocketSink sink,
        final @CheckForNull @WillNotClose InputService<JarDriverEntry> input)
throws IOException {
    final ZipInputService<JarDriverEntry> zis = (ZipInputService<JarDriverEntry>) input;
    return new MultiplexingOutputService<>(getPool(),
            new ZipOutputService<>(model, new RaesSocketSink(model, sink), zis, this));
}
OdfDriver.java 文件源码 项目:truevfs 阅读 32 收藏 0 点赞 0 评论 0
@Override
protected OutputService<JarDriverEntry> newOutput(
        final FsModel model,
        final FsOutputSocketSink sink,
        final @CheckForNull @WillNotClose InputService<JarDriverEntry> input)
throws IOException {
    final ZipInputService<JarDriverEntry> zis = (ZipInputService<JarDriverEntry>) input;
    final ZipOutputService<JarDriverEntry> zos = new ZipOutputService<>(model, sink, zis, this);
    final IoBufferPool pool = getPool();
    return null != zis && sink.getOptions().get(GROW)
            ? new MultiplexingOutputService<>(pool, zos)
            : new OdfOutputService(pool, zos);
}
AbstractZipOutputStream.java 文件源码 项目:truevfs 阅读 42 收藏 0 点赞 0 评论 0
/**
 * Constructs a raw ZIP output stream which decorates the given output
 * stream and optionally apppends to the given raw ZIP file.
 *
 * @param  sink the sink to write the ZIP file to.
 *         If {@code appendee} is not {@code null}, then this must be set
 *         up so that it appends to the same ZIP file from which
 *         {@code appendee} is reading.
 * @param  appendee the nullable raw ZIP file to append to.
 *         This may already be closed.
 * @param  param the parameters for writing the ZIP file.
 */
@CreatesObligation
protected AbstractZipOutputStream(
        final Sink sink,
        final @CheckForNull @WillNotClose AbstractZipFile<E> appendee,
        final ZipOutputStreamParameters param)
throws IOException {
    final OutputStream out = sink.stream();
    try {
        this.out = this.leos = null != appendee
                ? new AppendingLittleEndianOutputStream(out, appendee)
                : new LittleEndianOutputStream(out);
        if (null != appendee) {
            this.charset = appendee.getRawCharset();
            this.comment = appendee.getRawComment();
            final Map<String, E> entries = new LinkedHashMap<>(
                    HashMaps.initialCapacity(appendee.size() + param.getOverheadSize()));
            entries.putAll(appendee.getRawEntries());
            this.entries = entries;
        } else {
            this.charset = param.getCharset();
            this.entries = new LinkedHashMap<>(
                    HashMaps.initialCapacity(param.getOverheadSize()));
        }
        setMethod0(param.getMethod());
        setLevel0(param.getLevel());
    } catch (final Throwable ex) {
        try {
            out.close();
        } catch (final Throwable ex2) {
            ex.addSuppressed(ex2);
        }
        throw ex;
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号