Example usage for com.google.common.io Closeables closeQuietly

List of usage examples for com.google.common.io Closeables closeQuietly

Introduction

In this page you can find the example usage for com.google.common.io Closeables closeQuietly.

Prototype

public static void closeQuietly(@Nullable Reader reader) 

Source Link

Document

Closes the given Reader , logging any IOException that's thrown rather than propagating it.

Usage

From source file:com.cloudera.cdk.morphline.tika.decompress.EmbeddedExtractor.java

public boolean parseEmbedded(InputStream stream, Record record, String name, Command child) {
    // Use the delegate parser to parse this entry

    TemporaryResources tmp = new TemporaryResources();
    try {//  w ww  . j a v a  2  s  .c o m
        final TikaInputStream newStream = TikaInputStream.get(new CloseShieldInputStream(stream), tmp);
        if (stream instanceof TikaInputStream) {
            final Object container = ((TikaInputStream) stream).getOpenContainer();
            if (container != null) {
                newStream.setOpenContainer(container);
            }
        }
        record = record.copy();

        record.replaceValues(Fields.ATTACHMENT_BODY, newStream);
        record.removeAll(Fields.ATTACHMENT_MIME_TYPE);
        record.removeAll(Fields.ATTACHMENT_CHARSET);

        record.removeAll(Fields.ATTACHMENT_NAME);
        if (name != null && name.length() > 0) {
            record.put(Fields.ATTACHMENT_NAME, name);
        }

        return child.process(record);
        //    } catch (RuntimeException e) {
        //      
        //      // THIS IS THE DIFF WRT ParsingEmbeddedDocumentExtractor
        //      throw new MorphlineRuntimeException(e);
        //      
        //        // TODO: can we log a warning somehow?
        //        // Could not parse the entry, just skip the content
    } finally {
        Closeables.closeQuietly(tmp);
    }

}

From source file:org.apache.mahout.text.ChunkedWriter.java

@Override
public void close() {
    Closeables.closeQuietly(writer);
}

From source file:org.wso2.msf4j.conf.SSLHandlerFactory.java

private static KeyStore getKeyStore(File keyStore, String keyStorePassword) throws IOException {
    KeyStore ks = null;/*w  ww . j  a va 2 s.co m*/
    InputStream is = new FileInputStream(keyStore);
    try {
        ks = KeyStore.getInstance("JKS");
        ks.load(is, keyStorePassword.toCharArray());
    } catch (Exception ex) {
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new IOException(ex);
    } finally {
        Closeables.closeQuietly(is);
    }
    return ks;
}

From source file:net.sourceforge.vaticanfetcher.model.index.file.RarTree.java

protected ArchiveIterator<FileHeader> getArchiveIterator(File archiveFile, String archivePath)
        throws IOException, ArchiveEncryptedException {
    Archive archive = null;//  w  w w. j  a  v a  2 s.  c  o m
    try {
        archive = new Archive(archiveFile);
        if (archive.isEncrypted()) {
            Closeables.closeQuietly(archive);
            throw new ArchiveEncryptedException(archiveFile, archivePath);
        }
        final Archive fArchive = archive;
        return new ArchiveIterator<FileHeader>() {
            private FileHeader nextFileHeader = fArchive.nextFileHeader();

            public FileHeader next() {
                FileHeader fh = nextFileHeader;
                nextFileHeader = fArchive.nextFileHeader();
                return fh;
            }

            public boolean hasNext() {
                return nextFileHeader != null;
            }

            public void finished() {
                Closeables.closeQuietly(fArchive);
            }
        };
    } catch (RarException e) {
        Closeables.closeQuietly(archive);
        throw new IOException(e);
    } catch (RuntimeException e) {
        // J7Zip threw a NullPointerException, as reported in #3437670.
        Closeables.closeQuietly(archive);
        throw new IOException(e);
    }
}

From source file:org.richfaces.cdk.resource.writer.impl.CSSCompressingProcessor.java

@Override
public void process(String resourceName, InputStream in, OutputStream out, boolean closeAtFinish)
        throws IOException {
    Reader reader = null;/*from   www  .j a v  a  2 s .  c om*/
    Writer writer = null;

    try {
        reader = new InputStreamReader(in, charset);
        writer = new OutputStreamWriter(out, charset);

        new CssCompressor(reader).compress(writer, 0);
    } finally {
        Closeables.closeQuietly(reader);
        if (closeAtFinish) {
            Closeables.closeQuietly(writer);
        } else {
            writer.flush();
        }
    }
}

From source file:cogroo.uima.ae.NewTagsetBaselineCogrooAE.java

public static GrammarChecker createCogroo() throws ResourceInitializationException {
    InputStream in = ComponentFactory.class.getResourceAsStream("/models.xml");

    ComponentFactory factory = ComponentFactory.create(in);

    GrammarChecker cogroo;//from  w  w w .j  ava  2 s  .c o m

    try {
        cogroo = new GrammarChecker((Pipe) factory.createPipe());
        cogroo.resetIgnoredRules();

        //      String[] ignore = { "xml:17", "xml:21", "xml:117", "xml:118", "xml:124", "xml:103",
        //          "xml:104", "xml:105" };
        //      
        //      for (String string : ignore) {
        //        checker.ignoreRule(string);
        //      }
    } catch (IllegalArgumentException e) {
        throw new ResourceInitializationException(e);
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }

    Closeables.closeQuietly(in);

    return cogroo;
}

From source file:com.iadams.sonarqube.puppet.checks.MissingNewLineAtEndOfFileCheck.java

@Override
public void visitFile(AstNode astNode) {
    RandomAccessFile randomAccessFile = null;
    try {//from   ww w  . j  av  a 2  s .  c o m
        randomAccessFile = new RandomAccessFile(getContext().getFile(), "r");
        if (!endsWithNewline(randomAccessFile)) {
            addIssueOnFile(this, "Add an empty new line at the end of this file.");
        }
    } catch (IOException e) {
        throw new SonarException(e);
    } finally {
        Closeables.closeQuietly(randomAccessFile);
    }
}

From source file:com.enonic.cms.core.xslt.base.BaseXsltProcessor.java

@Override
public final String process(final Source xml) throws XsltProcessorException {
    StringWriter writer = new StringWriter();

    try {/*from  w  ww  .  jav a  2  s  . c o  m*/
        process(xml, writer);
    } finally {
        Closeables.closeQuietly(writer);
    }

    return writer.toString();
}

From source file:co.cask.cdap.logging.framework.LogFileOutputStream.java

LogFileOutputStream(Location location, Schema schema, int syncIntervalBytes, long createTime,
        Closeable closeable) throws IOException {
    this.location = location;
    this.schema = schema;
    this.closeable = closeable;
    try {/*from w w  w.j ava2 s  .c  om*/
        this.outputStream = location.getOutputStream();
        this.dataFileWriter = new DataFileWriter<>(new GenericDatumWriter<GenericRecord>(schema));
        this.dataFileWriter.create(schema, outputStream);
        this.dataFileWriter.setSyncInterval(syncIntervalBytes);
        this.createTime = createTime;
        this.fileSize = 0;
    } catch (IOException e) {
        Closeables.closeQuietly(outputStream);
        Closeables.closeQuietly(dataFileWriter);
        throw e;
    }
}

From source file:org.sonarqube.cppcheck.CppcheckXmlParser.java

public static Collection<Message> parse(@WillClose InputStream is) throws XMLStreamException {
    CppcheckXmlParser handler = new CppcheckXmlParser();
    try {//from  w w  w. j  a v  a 2 s  . c o  m
        new StaxParser(handler).parse(is);
    } finally {
        Closeables.closeQuietly(is);
    }
    return handler.result.build();
}