List of usage examples for com.google.common.io Closeables closeQuietly
public static void closeQuietly(@Nullable Reader reader)
From source file:org.deephacks.confit.internal.core.yaml.YamlBeanManagerSetup.java
private static void clearStorageFile(File dir, String contents, String fileName) { FileWriter writer = null;/*from ww w . ja v a2 s . com*/ try { // make sure dir exist if (!dir.exists()) { dir.mkdir(); } File file = new File(dir, fileName); if (!file.exists()) { file.createNewFile(); } writer = new FileWriter(new File(dir, fileName)); writer.write(contents); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { Closeables.closeQuietly(writer); } }
From source file:com.enonic.cms.framework.blob.BlobRecord.java
public final byte[] getAsBytes() throws BlobStoreException { final InputStream stream = getStream(); try {/*www . ja v a2 s . c o m*/ return ByteStreams.toByteArray(stream); } catch (IOException e) { throw new BlobStoreException("Failed to get bytes from blob [" + this.key + "]", e); } finally { Closeables.closeQuietly(stream); } }
From source file:org.kitesdk.apps.spi.PropertyFiles.java
public static Map<String, String> load(FileSystem fs, Path path) { InputStream stream = null;//from w w w .j a v a 2 s . co m try { stream = fs.open(path); return load(stream); } catch (FileNotFoundException e) { throw new AppException(e); } catch (IOException e) { throw new AppException(e); } finally { Closeables.closeQuietly(stream); } }
From source file:com.foundationdb.util.Exceptions.java
@SuppressWarnings("unused") public static void dumpTraceToFile(String dir, String include, String exclude) { StackTraceElement[] trace = Thread.currentThread().getStackTrace(); if (!match(trace, include, exclude)) return;//w w w. j a va 2 s .c o m String traceString = Strings.join(trace); FileWriter writer = null; try { File tmpFile = File.createTempFile("trace-", ".txt", new File(dir)); writer = new FileWriter(tmpFile); writer.write(traceString); } catch (IOException e) { logger.error("while outputting to " + dir, e); } finally { Closeables.closeQuietly(writer); } }
From source file:com.netflix.exhibitor.core.s3.PropertyBasedS3Credential.java
private static Properties loadProperties(File propertiesFile) throws IOException { Properties properties = new Properties(); InputStream in = new BufferedInputStream(new FileInputStream(propertiesFile)); try {// w w w . j av a 2 s . c o m properties.load(in); } finally { Closeables.closeQuietly(in); } return properties; }
From source file:net.sourceforge.docfetcher.model.parse.UtilParser.java
public static Source getSource(ZipFile file, String entryPath) throws IOException, ParseException { ZipEntry entry = file.getEntry(entryPath); if (entry == null) { // Apparently, ZipFile.getEntry expects forward slashes even on Windows entry = file.getEntry(entryPath.replace("\\", "/")); if (entry == null) { throw new ParseException(Msg.file_corrupted.get()); }/* w w w. j ava 2 s .c o m*/ } InputStream inputStream = file.getInputStream(entry); Source source = getSource(inputStream); Closeables.closeQuietly(inputStream); source.setLogger(null); return source; }
From source file:org.kitesdk.apps.spark.spi.SparkContextFactory.java
private static Properties loadSparkDefaults() { Properties defaults = new Properties(); InputStream stream = SparkContextFactory.class.getResourceAsStream("/kite-spark-defaults.properties"); try {//from ww w .j a va2s . c o m defaults.load(stream); } catch (IOException e) { throw new AppException(e); } finally { Closeables.closeQuietly(stream); } return defaults; }
From source file:com.metamx.druid.utils.CompressionUtils.java
public static long zip(File directory, File outputZipFile) throws IOException { if (!outputZipFile.getName().endsWith(".zip")) { log.warn("No .zip suffix[%s], putting files from [%s] into it anyway.", outputZipFile, directory); }//from ww w .ja v a 2 s . com final FileOutputStream out = new FileOutputStream(outputZipFile); try { final long retVal = zip(directory, out); out.close(); return retVal; } finally { Closeables.closeQuietly(out); } }
From source file:cc.recommenders.utils.Zips.java
public static void unzip(File source, File dest) throws IOException { ZipInputStream zis = null;//from ww w.j a va 2 s .c om try { InputSupplier<FileInputStream> fis = Files.newInputStreamSupplier(source); zis = new ZipInputStream(fis.getInput()); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (!entry.isDirectory()) { final File file = new File(dest, entry.getName()); Files.createParentDirs(file); Files.write(ByteStreams.toByteArray(zis), file); } } } finally { Closeables.closeQuietly(zis); } }
From source file:com.eviware.loadui.impl.reporting.ReportingManagerImpl.java
private static JasperPrint getJpFromFile(File file) { ObjectInputStream ois = null; try {//from w w w . j a va 2 s . com ois = new ObjectInputStream(new FileInputStream(file)); return (JasperPrint) ois.readObject(); } catch (IOException e) { return null; } catch (ClassNotFoundException e) { return null; } finally { Closeables.closeQuietly(ois); } }