javax.annotation.WillCloseWhenClosed Java Examples

The following examples show how to use javax.annotation.WillCloseWhenClosed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSVReader.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: MMapStringValueLookup.java    From imhotep with Apache License 2.0 5 votes vote down vote up
public MMapStringValueLookup(@WillCloseWhenClosed final BufferResource docIdToAddressBuffer,
                             @WillCloseWhenClosed final BufferResource stringValuesBuffer) {
    this.docIdToAddressBuffer = docIdToAddressBuffer;
    this.stringValuesBuffer = stringValuesBuffer;
    docIdToAddress = docIdToAddressBuffer.memory();
    stringValues = stringValuesBuffer.memory();
}
 
Example #3
Source File: SafeXMLStreamWriter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: Util.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Writer getWriter(@WillCloseWhenClosed OutputStream out) {
    return UTF8.writer(out);
}
 
Example #5
Source File: HashOutputStream.java    From bazel with Apache License 2.0 4 votes vote down vote up
public HashOutputStream(@WillCloseWhenClosed OutputStream delegate, Checksum checksum) {
  this.delegate = delegate;
  this.hasher = checksum.getKeyType().newHasher();
  this.code = checksum.getHashCode();
}
 
Example #6
Source File: ProgressInputStream.java    From bazel with Apache License 2.0 4 votes vote down vote up
InputStream create(@WillCloseWhenClosed InputStream delegate, URL url, URL originalUrl) {
  return new ProgressInputStream(
      locale, clock, eventHandler, PROGRESS_INTERVAL_MS, delegate, url, originalUrl);
}
 
Example #7
Source File: HttpStream.java    From bazel with Apache License 2.0 4 votes vote down vote up
HttpStream(@WillCloseWhenClosed InputStream delegate, URL url) {
  super(delegate);
  this.url = url;
}
 
Example #8
Source File: HashInputStream.java    From bazel with Apache License 2.0 4 votes vote down vote up
HashInputStream(@WillCloseWhenClosed InputStream delegate, Checksum checksum) {
  this.delegate = delegate;
  this.hasher = checksum.getKeyType().newHasher();
  this.code = checksum.getHashCode();
}
 
Example #9
Source File: InterruptibleInputStream.java    From bazel with Apache License 2.0 4 votes vote down vote up
InterruptibleInputStream(@WillCloseWhenClosed InputStream delegate) {
  this.delegate = delegate;
}
 
Example #10
Source File: SafeXMLStreamWriter.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static SafeXMLStreamWriter create (@Nonnull @WillCloseWhenClosed final Writer aWriter,
                                          @Nonnull final IXMLWriterSettings aSettings)
{
  return new SafeXMLStreamWriter (new XMLEmitter (aWriter, aSettings));
}
 
Example #11
Source File: ImprovedInputStream.java    From nomulus with Apache License 2.0 4 votes vote down vote up
public ImprovedInputStream(String name, @WillCloseWhenClosed InputStream out) {
  this(name, out, true);
}
 
Example #12
Source File: ImprovedOutputStream.java    From nomulus with Apache License 2.0 4 votes vote down vote up
public ImprovedOutputStream(String name, @WillCloseWhenClosed OutputStream out) {
  this(name, out, true);
}
 
Example #13
Source File: BufferedIo.java    From bundletool with Apache License 2.0 4 votes vote down vote up
@MustBeClosed
public static BufferedReader reader(@WillCloseWhenClosed InputStream is) {
  return new BufferedReader(new InputStreamReader(is, UTF_8));
}
 
Example #14
Source File: Util.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Reader getReader(@WillCloseWhenClosed InputStream in) {
    return UTF8.reader(in);
}
 
Example #15
Source File: SourceFinder.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ZipSourceRepository(@WillCloseWhenClosed ZipFile zipFile) {
    this.zipFile = zipFile;
}
 
Example #16
Source File: SourceFinder.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setBase(@WillCloseWhenClosed SourceRepository base) {
    this.base = base;
    ready.countDown();
}
 
Example #17
Source File: OutputStreamXMLOutput.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public OutputStreamXMLOutput(@WillCloseWhenClosed Writer writer, String stylesheet) {
    this.out = writer;
    this.nestingLevel = 0;
    this.newLine = true;
    this.stylesheet = stylesheet;
}
 
Example #18
Source File: UTF8.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static BufferedReader bufferedReader(@WillCloseWhenClosed InputStream in) {
    return new BufferedReader(reader(in));
}
 
Example #19
Source File: UTF8.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Reader reader(@WillCloseWhenClosed InputStream in) {
    return new InputStreamReader(in, StandardCharsets.UTF_8);
}
 
Example #20
Source File: UserTextFile.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static BufferedReader bufferedReader(@WillCloseWhenClosed InputStream in) {
    return new BufferedReader(reader(in));
}
 
Example #21
Source File: UserTextFile.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Reader reader(@WillCloseWhenClosed InputStream in) {
    return new InputStreamReader(in, charset);
}
 
Example #22
Source File: BufferedIo.java    From bundletool with Apache License 2.0 4 votes vote down vote up
@MustBeClosed
static OutputStream makeBuffered(@WillCloseWhenClosed OutputStream os) {
  return (os instanceof BufferedOutputStream || os instanceof ByteArrayOutputStream)
      ? os
      : new BufferedOutputStream(os);
}
 
Example #23
Source File: BufferedIo.java    From bundletool with Apache License 2.0 4 votes vote down vote up
@MustBeClosed
static InputStream makeBuffered(@WillCloseWhenClosed InputStream is) {
  return (is instanceof BufferedInputStream || is instanceof ByteArrayInputStream)
      ? is
      : new BufferedInputStream(is);
}
 
Example #24
Source File: OutputStreamXMLOutput.java    From spotbugs with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructor.
 *
 * @param os
 *            OutputStream to write XML output to
 * @param stylesheet
 *            name of stylesheet
 */
public OutputStreamXMLOutput(@WillCloseWhenClosed OutputStream os, String stylesheet) {
    this.out = new OutputStreamWriter(os, StandardCharsets.UTF_8);
    this.nestingLevel = 0;
    this.newLine = true;
    this.stylesheet = stylesheet;
}
 
Example #25
Source File: CSVWriter.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs {@link CSVWriter} with all default settings.
 *
 * @param aWriter
 *        the writer to an underlying CSV source. May not be <code>null</code>
 *        .
 */
public CSVWriter (@Nonnull @WillCloseWhenClosed final Writer aWriter)
{
  ValueEnforcer.notNull (aWriter, "Writer");
  m_aRawWriter = aWriter;
  m_aPW = new PrintWriter (aWriter);
}
 
Example #26
Source File: OutputStreamXMLOutput.java    From spotbugs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param writer
 *            Writer to write XML output to
 */
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
public OutputStreamXMLOutput(@WillCloseWhenClosed Writer writer) {
    this(writer, null);
}
 
Example #27
Source File: CSVReader.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs CSVReader using a comma for the separator.
 *
 * @param aReader
 *        the reader to an underlying CSV source.
 */
public CSVReader (@Nonnull @WillCloseWhenClosed final Reader aReader)
{
  this (aReader, new CSVParser (), CCSV.DEFAULT_KEEP_CR);
}
 
Example #28
Source File: CSVReader.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs {@link CSVReader} using a comma for the separator.
 *
 * @param aReader
 *        the reader to an underlying CSV source.
 * @param bKeepCR
 *        <code>true</code> to keep carriage returns in data read,
 *        <code>false</code> otherwise
 */
public CSVReader (@Nonnull @WillCloseWhenClosed final Reader aReader, final boolean bKeepCR)
{
  this (aReader, new CSVParser (), bKeepCR);
}
 
Example #29
Source File: OutputStreamXMLOutput.java    From spotbugs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param os
 *            OutputStream to write XML output to
 */
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
public OutputStreamXMLOutput(@WillCloseWhenClosed OutputStream os) {
    this(os, null);
}