List of usage examples for com.google.common.io Closeables closeQuietly
public static void closeQuietly(@Nullable Reader reader)
From source file:com.netflix.servo.example.ExitHandler.java
protected void handleImpl(HttpExchange exchange) throws IOException { exchange.sendResponseHeaders(200, 0); exchange.close(); Closeables.closeQuietly(server); }
From source file:org.apache.mahout.graph.common.GraphUtils.java
public static int indexVertices(Configuration conf, Path verticesPath, Path indexPath) throws IOException { FileSystem fs = FileSystem.get(verticesPath.toUri(), conf); SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, indexPath, IntWritable.class, Vertex.class); int index = 0; try {// w ww . j a v a2 s . c om for (FileStatus fileStatus : fs.listStatus(verticesPath)) { InputStream in = fs.open(fileStatus.getPath()); try { for (String line : new FileLineIterable(in)) { writer.append(new IntWritable(index++), new Vertex(Long.parseLong(line))); } } finally { Closeables.closeQuietly(in); } } } finally { Closeables.closeQuietly(writer); } return index; }
From source file:com.github.zhongl.io.FileChannels.java
private static <T> T read(FileInputStream stream, FileChannelFunction<T> function) throws IOException { try {/*from w w w .ja va2s. c o m*/ return read(stream.getChannel(), function); } finally { Closeables.closeQuietly(stream); } }
From source file:de.fanero.uncompress.stream.OneEntryArchiveInputStream.java
@Override public ArchiveEntry getNextEntry() throws IOException { Closeables.closeQuietly(in); ArchiveEntry entry = archiveEntry;// ww w.j av a 2s .c o m archiveEntry = null; in = EmptyArchiveInputStream.getInstance(); return entry; }
From source file:cff.bench.convert.csv.ConvertUtils.java
private static String readFile(String path) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(path)); StringBuilder stringBuilder = new StringBuilder(); try {/* ww w.j a v a 2s . c om*/ String line = null; String ls = System.getProperty("line.separator"); while ((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); } } finally { Closeables.closeQuietly(reader); } return stringBuilder.toString(); }
From source file:fi.luontola.buildtest.StubClasses.java
@Override public Iterator<ClassNode> iterator() { final Iterator<Class<?>> it = classes.iterator(); return new AbstractIterator<ClassNode>() { @Override//from w w w . j a va 2 s .co m protected ClassNode computeNext() { if (!it.hasNext()) { return endOfData(); } Class<?> clazz = it.next(); InputStream in = getClass().getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".class"); try { return AsmUtils.readClass(in); } catch (IOException e) { throw new RuntimeException(e); } finally { Closeables.closeQuietly(in); } } }; }
From source file:org.geogit.rest.repository.SendObjectResource.java
public void post(Representation entity) { InputStream input = null;//from w ww .j a v a2 s. c o m try { input = getRequest().getEntity().getStream(); final GeoGIT ggit = getGeogit(getRequest()).get(); final BinaryPackedObjects unpacker = new BinaryPackedObjects(ggit.getRepository().getObjectDatabase()); unpacker.ingest(input); } catch (IOException e) { throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e); } finally { if (input != null) Closeables.closeQuietly(input); } }
From source file:org.prebake.service.LogRecordWriter.java
public void close() { if (out instanceof Closeable) { Closeables.closeQuietly((Closeable) out); } }
From source file:SimpleProc.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Closeable closeable = new StringReader("example"); Closeables.closeQuietly(closeable); return false; }
From source file:org.stjs.testing.driver.StreamUtils.java
private static long getResourceSize(ClassLoader classLoader, String path) throws IOException { final InputStream is = classLoader.getResourceAsStream(path); try {// w w w .jav a2 s. com // TODO improve this long n = 0; while (is.read() >= 0) { n++; } return n; } finally { Closeables.closeQuietly(is); } }