本文整理汇总了Java中javax.annotation.WillNotClose类的典型用法代码示例。如果您正苦于以下问题:Java WillNotClose类的具体用法?Java WillNotClose怎么用?Java WillNotClose使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WillNotClose类属于javax.annotation包,在下文中一共展示了WillNotClose类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAhead
import javax.annotation.WillNotClose; //导入依赖的package包/类
/**
* 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;
}
}
示例2: fetch
import javax.annotation.WillNotClose; //导入依赖的package包/类
/**
* 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);
}
}
}
示例3: openDecryptor
import javax.annotation.WillNotClose; //导入依赖的package包/类
/**
* 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);
}
示例4: RydeTarOutputStream
import javax.annotation.WillNotClose; //导入依赖的package包/类
/**
* 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);
}
}
示例5: decodeInto
import javax.annotation.WillNotClose; //导入依赖的package包/类
@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;
}
示例6: queryStatement
import javax.annotation.WillNotClose; //导入依赖的package包/类
/**
* 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();
}
示例7: getValues
import javax.annotation.WillNotClose; //导入依赖的package包/类
@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);
}
}
示例8: encode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例9: encode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例10: decode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例11: encode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例12: decode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例13: encode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例14: encode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}
示例15: decode
import javax.annotation.WillNotClose; //导入依赖的package包/类
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);
}
}