List of usage examples for com.google.common.io Closeables closeQuietly
public static void closeQuietly(@Nullable Reader reader)
From source file:org.sonar.plugins.erlang.cover.CoverDataFileParser.java
public static List<ErlangFileCoverage> parse(File inFile) throws IOException { InputStream fin = new FileInputStream(inFile); try {//from w w w .j av a 2 s . c o m InputStream in = new BufferedInputStream(fin); try { return parse(in); } finally { Closeables.closeQuietly(in); } } finally { Closeables.closeQuietly(fin); } }
From source file:org.eclipse.rcptt.launching.autdetails.ZipAutDetailsProcessor.java
public void addFile(String name, InputStream in) { try {//from w w w .j a va2 s . c o m zout.putNextEntry(new ZipEntry(name)); FileUtil.copyNoClose(in, zout); zout.closeEntry(); } catch (IOException e) { Q7LaunchingPlugin.log(e); } finally { Closeables.closeQuietly(in); } }
From source file:com.netflix.exhibitor.core.index.IndexMetaData.java
public static IndexMetaData read(File from) throws Exception { DateFormat format = DateFormat.getDateTimeInstance(); Properties properties = new Properties(); InputStream in = new BufferedInputStream(new FileInputStream(from)); try {/*from w w w . j a va 2s. c o m*/ properties.load(in); } finally { Closeables.closeQuietly(in); } String version = properties.getProperty(PROPERTY_VERSION, "0"); if (!version.equals(Integer.toString(VERSION))) { throw new Exception("Unknown version: " + version); } return new IndexMetaData(format.parse(properties.getProperty(PROPERTY_FROM)), format.parse(properties.getProperty(PROPERTY_TO)), Integer.parseInt(properties.getProperty(PROPERTY_COUNT))); }
From source file:com.netflix.curator.ensemble.exhibitor.DefaultExhibitorRestClient.java
@Override public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception { URI uri = new URI(useSsl ? "https" : "http", null, hostname, port, uriPath, null, null); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.addRequestProperty("Accept", mimeType); StringBuilder str = new StringBuilder(); InputStream in = new BufferedInputStream(connection.getInputStream()); try {// w w w . j a v a2 s . co m for (;;) { int b = in.read(); if (b < 0) { break; } str.append((char) (b & 0xff)); } } finally { Closeables.closeQuietly(in); } return str.toString(); }
From source file:io.smartspaces.util.web.UrlConnectionUrlReader.java
@Override public <T> T read(String url, UrlReaderProcessor<T> processor) { BufferedReader reader = null; try {/*from www. jav a2 s . co m*/ URL u = new URL(url); URLConnection connection = u.openConnection(); connection.setConnectTimeout(connectTimeout); reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); return processor.process(reader); } catch (Throwable e) { throw new SmartSpacesException(String.format("Could not process URL contents for %s", url), e); } finally { Closeables.closeQuietly(reader); } }
From source file:io.pcp.parfait.dxm.PcpConfig.java
public String getValue(String key) { Properties properties = new Properties(); File configuration = getConfigFile(); InputStream is = null;/*w ww. j a v a 2s . co m*/ String value = System.getenv(key); if (value != null) { return value; } try { is = new FileInputStream(configuration); properties.load(is); value = properties.get(key).toString(); } catch (FileNotFoundException e) { } catch (IOException e) { // just drop these, and go with defaults } finally { Closeables.closeQuietly(is); } return value; }
From source file:org.sonar.plugins.pmd.SunConventionsProfile.java
@Override public RulesProfile createProfile(ValidationMessages validation) { Reader config = null;//from ww w .j a v a 2 s. c o m try { config = new InputStreamReader( this.getClass().getResourceAsStream("/org/sonar/plugins/pmd/profile-sun-conventions.xml")); RulesProfile profile = importer.importProfile(config, validation); profile.setLanguage(Java.KEY); profile.setName(RulesProfile.SUN_CONVENTIONS_NAME); return profile; } finally { Closeables.closeQuietly(config); } }
From source file:org.kitesdk.apps.test.apps.DynamicInputOutputJob.java
@Override public void runJob(Map params, JobContext jobContext, Instant nominalTime) { View output = (View) params.get("output"); DatasetWriter<GenericRecord> writer = output.newWriter(); // Simply write all of the input datasets to the output. for (Map.Entry<String, View> param : ((Map<String, View>) params).entrySet()) { if (!param.getKey().equals("output")) { DatasetReader<GenericRecord> reader = param.getValue().newReader(); try { while (reader.hasNext()) { writer.write(reader.next()); }//from w w w . j av a 2s. c om } finally { Closeables.closeQuietly(reader); } } } Closeables.closeQuietly(writer); }
From source file:com.continuuity.weave.yarn.ResourceReportClient.java
/** * Returns the resource usage of the application fetched from the resource endpoint URL. * @return A {@link ResourceReport} or {@code null} if failed to fetch the report. *///w w w. j a v a 2s . com public ResourceReport get() { try { Reader reader = new BufferedReader(new InputStreamReader(resourceUrl.openStream(), Charsets.UTF_8)); try { return reportAdapter.fromJson(reader); } finally { Closeables.closeQuietly(reader); } } catch (Exception e) { LOG.error("Exception getting resource report from {}.", resourceUrl, e); return null; } }
From source file:com.mucommander.ui.viewer.text.TextEditorImpl.java
void read(AbstractFile file, String encoding) throws IOException { InputStream input = file.getInputStream(); // If the encoding is UTF-something, wrap the stream in a BOMInputStream to filter out the byte-order mark // (see ticket #245) if (encoding.toLowerCase().startsWith("utf")) { input = new BOMInputStream(input); }/*from w w w.j a v a 2 s. com*/ BufferedReader isr = new BufferedReader(new InputStreamReader(input, encoding), 4096); try { textArea.read(isr, null); } finally { Closeables.closeQuietly(isr); } // Move cursor to the top textArea.setCaretPosition(0); }