Package com.google.common.io

Examples of com.google.common.io.Closer


            String base = url.getFile();
            base = base.substring(base.lastIndexOf('/') + 1);
            mNameToFile.put(base, new File(url.toExternalForm()));

            File target = new File(resourceDir, base);
            Closer closer = Closer.create();
            try {
                FileOutputStream output = closer.register(new FileOutputStream(target));
                InputStream input = closer.register(url.openStream());
                ByteStreams.copy(input, output);
            } catch (Throwable e) {
                closer.rethrow(e);
            } finally {
                closer.close();
            }
            return resourceDir.getName() + '/' + encodeUrl(base);
        }
        return null;
    }
View Full Code Here


            projects.add(new ProjectEntry(fileName, projectErrorCount, projectWarningCount,
                    relative));
        }

        Closer closer = Closer.create();
        // Write overview index?
        try {
            closer.register(mWriter);
            writeOverview(errorCount, warningCount, projects);
        } catch (Throwable e) {
            throw closer.rethrow(e);
        } finally {
            closer.close();
        }

        if (mDisplayEmpty || errorCount > 0 || warningCount > 0) {
            File index = new File(mDir, INDEX_NAME);
            String url = SdkUtils.fileToUrlString(index.getAbsoluteFile());
View Full Code Here

  /**
   * Check to see if there was an error processing an rrdtool command
   */
  private void checkErrorStream(Process process) throws Exception {
    Closer closer = Closer.create();
    try {
      InputStream is = closer.register(process.getErrorStream());
      // rrdtool should use platform encoding (unless you did something
      // very strange with your installation of rrdtool). So let's be
      // explicit and use the presumed correct encoding to read errors.
      InputStreamReader isr = closer.register(new InputStreamReader(is, Charset.defaultCharset()));
      BufferedReader br = closer.register(new BufferedReader(isr));
      StringBuilder sb = new StringBuilder();
      String line;
      while ((line = br.readLine()) != null) {
        sb.append(line);
      }
      if (sb.length() > 0) {
        throw new RuntimeException(sb.toString());
      }
    } catch (Throwable t) {
      throw closer.rethrow(t);
    } finally {
      closer.close();
    }
  }
View Full Code Here

TOP

Related Classes of com.google.common.io.Closer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.