/** * 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; } }
/** * 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); } } }
/** * 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); }
/** * 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); } }
@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; }
/** * 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(); }
@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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
/** * 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; } }
/** * 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; }
/** * 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; }
@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; } }
@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; } }
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(); } }
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; }
@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()); }
@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()); }
/** * {@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); }
@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)); }
@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); }
/** * 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; } }
private void unpack(final @WillNotClose TarArchiveInputStream tain) throws IOException { final TarDriver driver = this.driver; final IoBufferPool pool = driver.getPool(); for ( TarArchiveEntry tinEntry; null != (tinEntry = tain.getNextTarEntry()); ) { final String name = name(tinEntry); TarDriverEntry entry = entries.get(name); if (null != entry) entry.release(); entry = driver.newEntry(name, tinEntry); if (!tinEntry.isDirectory()) { final IoBuffer buffer = pool.allocate(); entry.setBuffer(buffer); try { try (OutputStream out = buffer.output().stream(null)) { Streams.cat(tain, out); } } catch (final Throwable ex) { try { buffer.release(); } catch (final Throwable ex2) { ex.addSuppressed(ex2); } throw ex; } } entries.put(name, entry); } }
/** * Returns a newly created and validated {@link TarArchiveInputStream}. * This method performs a simple validation by computing the checksum * for the first record only. * This method is required because the {@code TarArchiveInputStream} * unfortunately does not do any validation! * * @param in the stream to read from. * @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 TarArchiveInputStream newValidatedTarArchiveInputStream( final @WillNotClose InputStream in) throws EOFException, IOException { final byte[] buf = new byte[DEFAULT_RCDSIZE]; final InputStream vin = readAhead(in, buf); // If the record is the null record, the TAR file is empty and we're // done with validating. if (!Arrays.equals(buf, NULL_RECORD)) { final long expected; try { expected = TarUtils.parseOctal(buf, CHECKSUM_OFFSET, 8); } catch (final IllegalArgumentException ex) { throw new TarException("Invalid initial record in TAR file!", ex); } for (int i = 0; i < 8; i++) buf[CHECKSUM_OFFSET + i] = ' '; final long actual = TarUtils.computeCheckSum(buf); if (expected != actual) throw new TarException( "Invalid initial record in TAR file: Expected / actual checksum : " + expected + " / " + actual + "!"); } return new TarArchiveInputStream( vin, DEFAULT_BLKSIZE, DEFAULT_RCDSIZE, driver.getEncoding()); }
@Override protected OutputService<TarDriverEntry> newOutput( final FsModel model, final FsOutputSocketSink sink, final @CheckForNull @WillNotClose InputService<TarDriverEntry> input) throws IOException { return new MultiplexingOutputService<>(getPool(), new TarOutputService(model, sink, this)); }
@CreatesObligation public ZipOutputService( final FsModel model, final FsOutputSocketSink sink, final @CheckForNull @WillNotClose ZipInputService<E> source, final AbstractZipDriver<E> driver) throws IOException { super( sink, null != source && sink.getOptions().get(GROW) ? source : null, driver); this.driver = driver; try { this.model = Objects.requireNonNull(model); if (null != source) { if (!sink.getOptions().get(GROW)) { // Retain comment and preamble of input ZIP archive. super.setComment(source.getComment()); if (0 < source.getPreambleLength()) { try (final InputStream in = source.getPreambleInputStream()) { Streams.cat(in, source.offsetsConsiderPreamble() ? this : out); } } } // Retain postamble of input ZIP file. if (0 < source.getPostambleLength()) { this.postamble = getPool().allocate(); Streams.copy( source.getPostambleInputStream(), this.postamble.output().stream(null)); } } } catch (final Throwable ex) { try { super.close(); } catch (final Throwable ex2) { ex.addSuppressed(ex2); } throw ex; } }
@Override @CreatesObligation protected OutputService<E> newOutput( FsModel model, FsOutputSocketSink sink, final @CheckForNull @WillNotClose InputService<E> input) throws IOException { final ZipInputService<E> zis = (ZipInputService<E>) input; return new MultiplexingOutputService<>(getPool(), new ZipOutputService<>(model, sink, zis, this)); }
/** * Opens a new {@link Encryptor} (Writing Step 1/3) * * <p>This is the first step in creating a ghostryde file. After this method, you'll want to * call {@link #openCompressor(Encryptor)}. * * @param os is the upstream {@link OutputStream} to which the result is written. * @param publicKey is the public encryption key of the recipient. * @throws IOException * @throws PGPException */ @CheckReturnValue public Encryptor openEncryptor(@WillNotClose OutputStream os, PGPPublicKey publicKey) throws IOException, PGPException { PGPEncryptedDataGenerator encryptor = new PGPEncryptedDataGenerator( new JcePGPDataEncryptorBuilder(CIPHER) .setWithIntegrityPacket(USE_INTEGRITY_PACKET) .setSecureRandom(getRandom()) .setProvider(PROVIDER_NAME)); encryptor.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey)); return new Encryptor(encryptor.open(os, new byte[bufferSize])); }
/** * Create a signer that wraps {@code os} and generates a detached signature using * {@code signingKey}. After closing, you should call {@link #getSignature()} to get the detached * signature. * * @param os is the upstream {@link OutputStream} which is not closed by this object * @throws RuntimeException to rethrow {@link PGPException} */ public RydePgpSigningOutputStream( @WillNotClose OutputStream os, PGPKeyPair signingKey) { super(os, false, -1); try { signer = new PGPSignatureGenerator( new BcPGPContentSignerBuilder(RSA_GENERAL, SHA256)); signer.init(BINARY_DOCUMENT, signingKey.getPrivateKey()); } catch (PGPException e) { throw new RuntimeException(e); } addUserInfoToSignature(signingKey.getPublicKey(), signer); }
/** * Creates a new instance for a particular file. * * @param os is the upstream {@link OutputStream} which is not closed by this object * @throws IllegalArgumentException if {@code filename} isn't a {@code .tar} file * @throws RuntimeException to rethrow {@link IOException} */ public RydePgpFileOutputStream( @Provided @Config("rdeRydeBufferSize") Integer bufferSize, @WillNotClose OutputStream os, DateTime modified, String filename) { super(createDelegate(bufferSize, os, modified, filename)); }
private void loadImpl(@WillNotClose Reader reader) { Config fromYaml = Serialization.getGlobal().fromYaml(reader, this.template.getConfigType()); ConfigInvocationHandler invocationHandler = (ConfigInvocationHandler) Proxy.getInvocationHandler(fromYaml); this.predefinedValues.putAll(invocationHandler.predefinedValues); this.dynamicValues.putAll(invocationHandler.dynamicValues); this.simpleDynamicValues.putAll(invocationHandler.simpleDynamicValues); }
LZVNBlockDecoder init(LZVNBlockHeader header, @WillNotClose ReadableByteChannel ch) throws IOException { initBuffer(header.nPayloadBytes()); IO.readFully(ch, bb).rewind(); l = 0; m = 0; d = -1; return this; }