/**
* 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);
}
}
java类javax.annotation.WillCloseWhenClosed的实例源码
RaesReadOnlyChannel.java 文件源码
项目:truevfs
阅读 31
收藏 0
点赞 0
评论 0
CSVReader.java 文件源码
项目:ph-commons
阅读 46
收藏 0
点赞 0
评论 0
/**
* 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;
}
ThrowingInputStream.java 文件源码
项目:truevfs
阅读 35
收藏 0
点赞 0
评论 0
@CreatesObligation
public ThrowingInputStream( final @WillCloseWhenClosed InputStream in,
final @CheckForNull FsThrowManager control) {
super(in);
this.control = null != control
? control
: FsTestConfig.get().getThrowControl();
}
ThrowingSeekableChannel.java 文件源码
项目:truevfs
阅读 30
收藏 0
点赞 0
评论 0
@CreatesObligation
public ThrowingSeekableChannel(
final @WillCloseWhenClosed SeekableByteChannel channel,
final @CheckForNull FsThrowManager control) {
super(channel);
this.control = null != control
? control
: FsTestConfig.get().getThrowControl();
}
ThrowingOutputStream.java 文件源码
项目:truevfs
阅读 29
收藏 0
点赞 0
评论 0
@CreatesObligation
public ThrowingOutputStream(final @WillCloseWhenClosed OutputStream out,
final @CheckForNull FsThrowManager control) {
super(out);
this.control = null != control
? control
: FsTestConfig.get().getThrowControl();
}
MultiplexingOutputService.java 文件源码
项目:truevfs
阅读 42
收藏 0
点赞 0
评论 0
/**
* 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);
}
CipherReadOnlyChannel.java 文件源码
项目:truevfs
阅读 35
收藏 0
点赞 0
评论 0
/**
* 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);
}
CipherReadOnlyChannel.java 文件源码
项目:truevfs
阅读 29
收藏 0
点赞 0
评论 0
/**
* 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;
}
CipherOutputStream.java 文件源码
项目:truevfs
阅读 41
收藏 0
点赞 0
评论 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);
}
AbstractZipFile.java 文件源码
项目:truevfs
阅读 29
收藏 0
点赞 0
评论 0
@CreatesObligation
SafeBufferedReadOnlyChannel(
final @WillCloseWhenClosed SeekableByteChannel channel,
final long size) {
super(channel);
this.size = size;
}
WebfilesWriter.java 文件源码
项目:rules_closure
阅读 104
收藏 0
点赞 0
评论 0
/**
* 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);
}
AutoCloseableHtmlStreamRenderer.java 文件源码
项目:java-html-sanitizer
阅读 30
收藏 0
点赞 0
评论 0
static AutoCloseableHtmlStreamRenderer createAutoCloseableHtmlStreamRenderer(
@WillCloseWhenClosed
Appendable output, Handler<? super IOException> errorHandler,
Handler<? super String> badHtmlHandler) {
return new AutoCloseableHtmlStreamRenderer(
output, errorHandler, badHtmlHandler);
}
AutoCloseableHtmlStreamRenderer.java 文件源码
项目:java-html-sanitizer
阅读 26
收藏 0
点赞 0
评论 0
private AutoCloseableHtmlStreamRenderer(
@WillCloseWhenClosed
Appendable output, Handler<? super IOException> errorHandler,
Handler<? super String> badHtmlHandler) {
super(output, errorHandler, badHtmlHandler);
this.closeable = output;
}
HtmlStreamRenderer.java 文件源码
项目:java-html-sanitizer
阅读 34
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
HtmlStreamRenderer.java 文件源码
项目:java-html-sanitizer
阅读 35
收藏 0
点赞 0
评论 0
CloseableHtmlStreamRenderer(
@WillCloseWhenClosed
Appendable output, Handler<? super IOException> errorHandler,
Handler<? super String> badHtmlHandler) {
super(output, errorHandler, badHtmlHandler);
this.closeable = (Closeable) output;
}
LKFileUtils.java 文件源码
项目:C1_ParknShop
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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;
}
SafeXMLStreamWriter.java 文件源码
项目:ph-commons
阅读 29
收藏 0
点赞 0
评论 0
@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);
}
MMapStringValueLookup.java 文件源码
项目:imhotep
阅读 62
收藏 0
点赞 0
评论 0
public MMapStringValueLookup(@WillCloseWhenClosed final BufferResource docIdToAddressBuffer,
@WillCloseWhenClosed final BufferResource stringValuesBuffer) {
this.docIdToAddressBuffer = docIdToAddressBuffer;
this.stringValuesBuffer = stringValuesBuffer;
docIdToAddress = docIdToAddressBuffer.memory();
stringValues = stringValuesBuffer.memory();
}
ThrowingOutputService.java 文件源码
项目:truevfs
阅读 34
收藏 0
点赞 0
评论 0
public ThrowingOutputService(
final @WillCloseWhenClosed OutputService<E> service) {
this(service, null);
}
ThrowingOutputService.java 文件源码
项目:truevfs
阅读 31
收藏 0
点赞 0
评论 0
public ThrowingOutputService(
final @WillCloseWhenClosed OutputService<E> service,
final @CheckForNull FsTestConfig config) {
super(service);
this.config = null != config ? config : FsTestConfig.get();
}
ThrowingInputService.java 文件源码
项目:truevfs
阅读 33
收藏 0
点赞 0
评论 0
public ThrowingInputService(
final @WillCloseWhenClosed InputService<E> service) {
this(service, null);
}
ThrowingInputService.java 文件源码
项目:truevfs
阅读 39
收藏 0
点赞 0
评论 0
public ThrowingInputService(
final @WillCloseWhenClosed InputService<E> service,
final @CheckForNull FsTestConfig config) {
super(service);
this.config = null != config ? config : FsTestConfig.get();
}
ThrowingInputStream.java 文件源码
项目:truevfs
阅读 31
收藏 0
点赞 0
评论 0
@CreatesObligation
public ThrowingInputStream(@WillCloseWhenClosed InputStream in) {
this(in, null);
}
ThrowingSeekableChannel.java 文件源码
项目:truevfs
阅读 42
收藏 0
点赞 0
评论 0
@CreatesObligation
public ThrowingSeekableChannel(
@WillCloseWhenClosed SeekableByteChannel sbc) {
this(sbc, null);
}
ThrowingOutputStream.java 文件源码
项目:truevfs
阅读 34
收藏 0
点赞 0
评论 0
@CreatesObligation
public ThrowingOutputStream(@WillCloseWhenClosed OutputStream out) {
this(out, null);
}
MultiplexingOutputService.java 文件源码
项目:truevfs
阅读 30
收藏 0
点赞 0
评论 0
EntryOutputStream(final @WillCloseWhenClosed OutputStream out) {
super(out);
busy = true;
}
DummyByteChannelInputStream.java 文件源码
项目:truevfs
阅读 32
收藏 0
点赞 0
评论 0
@CreatesObligation
DummyByteChannelInputStream(
@WillCloseWhenClosed SeekableByteChannel channel) {
super(channel);
}
ZipInflaterInputStream.java 文件源码
项目:truevfs
阅读 29
收藏 0
点赞 0
评论 0
@CreatesObligation
ZipInflaterInputStream(@WillCloseWhenClosed InputStream in, int size) {
super(in, new Inflater(true), size);
}
AbstractZipOutputStream.java 文件源码
项目:truevfs
阅读 66
收藏 0
点赞 0
评论 0
AppendingLittleEndianOutputStream(
final @WillCloseWhenClosed OutputStream out,
final @WillNotClose AbstractZipFile<?> appendee) {
super(out);
super.written = appendee.getOffsetMapper().unmap(appendee.length());
}
CountingInputStream.java 文件源码
项目:truevfs
阅读 29
收藏 0
点赞 0
评论 0
@CreatesObligation
CountingInputStream(@WillCloseWhenClosed InputStream in) {
super(in);
}