Guava Closer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Closer class.

This code example shows how to use the following methods:register
      super(content);
   } 
 
   @Override 
   public InputStream openStream() throws IOException {
      return closer.register(content.openStream());
   } 
 
   @Override 
   public boolean isRepeatable() { 
      return true; 
   } 
 
   /** 
    * if we created the stream, then it is already consumed on close. 
    */ 
   @Override 
   public void release() { 
      closeQuietly(closer);
   } 
5
CodeRank
This code example shows how to use the following methods:close, rethrow
         * It ensures that suppressed exceptions from the Closeables are 
         * handled correctly. 
         */ 
        try { 
            try { 
                throw _closer.rethrow(exc, Exception.class);
            } finally { 
                _closer.close();
            } 
        } catch (Throwable t) {
            fail(t, attachment);
        } 
    } 
 
    private void fail(Throwable t, A attachment)
    { 
        try { 
            onFailure(t, attachment);
        } catch (Exception replacement) {
            if (replacement.getCause() == t) {
5
CodeRank
This code example shows how to use the following methods:close
    @Override 
    public final void close() 
    { 
        cancelAllQueries(); 
        try { 
            closer.close();
        } 
        catch (IOException e) {
            throw Throwables.propagate(e);
        } 
    } 
 
    private void cancelAllQueries() 
    { 
        QueryManager queryManager = coordinator.getQueryManager();
        for (QueryInfo queryInfo : queryManager.getAllQueryInfo()) {
            if (!queryInfo.getState().isDone()) {
                queryManager.cancelQuery(queryInfo.getQueryId());
            } 
        } 
4
CodeRank
This code example shows how to use the following methods:close
public class MorphEncodingToolTest extends RandomizedTest { 
    private Closer closer = Closer.create();
 
    @After 
    public void cleanup() throws IOException {
        closer.close();
    } 
     
	@Test
	public void testTool() throws Exception {
		// Create a simple plain text file. 
		File input = super.newTempFile();
		File output = super.newTempFile();
 
		// Populate the file with data. 
		PrintWriter w = 
		    new PrintWriter(
		        new OutputStreamWriter(
		            closer.register(new FileOutputStream(input)), "UTF-8"));
		w.println("passagère\tpassager\ttag");
3
CodeRank
See Code Examples for Guava Closer Methods: