List of usage examples for com.google.common.io Closer close
@Override public void close() throws IOException
From source file:org.glowroot.agent.live.ClasspathCache.java
private static void loadClassNamesFromJarFileInsideJarFile(File jarFile, String jarFileInsideJarFile, Location location, Multimap<String, Location> newClassNameLocations) throws IOException { URI uri;/*from w w w. j a v a 2 s . c o m*/ try { uri = new URI("jar", "file:" + jarFile.getPath() + "!/" + jarFileInsideJarFile, ""); } catch (URISyntaxException e) { // this is a programmatic error throw new RuntimeException(e); } Closer closer = Closer.create(); try { InputStream in = closer.register(uri.toURL().openStream()); JarInputStream jarIn = closer.register(new JarInputStream(in)); loadClassNamesFromJarInputStream(jarIn, "", location, newClassNameLocations); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
From source file:se.sics.datamodel.util.DMKeyFactory.java
private static byte[] serializeLexico(int val) throws IOException { Closer closer = Closer.create(); try {/*from ww w . j a v a 2s .c o m*/ ByteArrayOutputStream baos = closer.register(new ByteArrayOutputStream()); DataOutputStream w = closer.register(new DataOutputStream(baos)); byte sign = (val < 0 ? (byte) 0 : (byte) 1); int absVal = Math.abs(val); byte[] iVal = Ints.toByteArray(absVal); w.write(INDEXVAL_INT); w.write(sign); w.write(iVal); w.flush(); return baos.toByteArray(); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
From source file:se.sics.datamodel.util.DMKeyFactory.java
private static byte[] serializeLexico(long val) throws IOException { Closer closer = Closer.create(); try {/*from w ww. j a va 2 s . com*/ ByteArrayOutputStream baos = closer.register(new ByteArrayOutputStream()); DataOutputStream w = closer.register(new DataOutputStream(baos)); byte sign = (val < 0 ? (byte) 0 : (byte) 1); long absVal = Math.abs(val); byte[] iVal = Longs.toByteArray(absVal); w.write(INDEXVAL_LONG); w.write(sign); w.write(iVal); w.flush(); return baos.toByteArray(); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
From source file:org.glowroot.agent.live.ClasspathCache.java
private static void loadClassNamesFromDirectoryInsideJarFile(File jarFile, String directoryInsideJarFile, Location location, Multimap<String, Location> newClassNameLocations) throws IOException { Closer closer = Closer.create(); try {/*from w w w. j a v a 2s. c o m*/ InputStream in = closer.register(new FileInputStream(jarFile)); JarInputStream jarIn = closer.register(new JarInputStream(in)); loadClassNamesFromJarInputStream(jarIn, directoryInsideJarFile, location, newClassNameLocations); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
From source file:tachyon.client.file.TachyonFileSystemUtils.java
/** * Persist the given file to the under file system. * * @param tfs {@link TachyonFileSystem} to carry out tachyon operations * @param file the file to persist//from w w w . ja va 2s . c om * @param fileInfo the file info of the file * @param tachyonConf TachyonConf object * @return the size of the file persisted * @throws IOException if an I/O error occurs * @throws FileDoesNotExistException if the given file does not exist * @throws TachyonException if an unexpected Tachyon error occurs */ public static long persistFile(TachyonFileSystem tfs, TachyonFile file, FileInfo fileInfo, TachyonConf tachyonConf) throws IOException, FileDoesNotExistException, TachyonException { // TODO(manugoyal) move this logic to the worker, as it deals with the under file system Closer closer = Closer.create(); long ret; try { InStreamOptions inStreamOptions = new InStreamOptions.Builder(tachyonConf) .setTachyonStorageType(TachyonStorageType.NO_STORE).build(); FileInStream in = closer.register(tfs.getInStream(file, inStreamOptions)); TachyonURI dstPath = new TachyonURI(fileInfo.getUfsPath()); UnderFileSystem ufs = UnderFileSystem.get(dstPath.getPath(), tachyonConf); String parentPath = dstPath.getParent().getPath(); if (!ufs.exists(parentPath) && !ufs.mkdirs(parentPath, true)) { throw new IOException("Failed to create " + parentPath); } OutputStream out = closer.register(ufs.create(dstPath.getPath())); ret = IOUtils.copyLarge(in, out); } catch (Exception e) { throw closer.rethrow(e); } finally { closer.close(); } // Tell the master to mark the file as persisted tfs.setState(file, (new SetStateOptions.Builder()).setPersisted(true).build()); return ret; }
From source file:se.sics.datamodel.util.DMKeyFactory.java
private static byte[] serializeLexico(String val) throws IOException { Closer closer = Closer.create(); try {/*w w w . jav a 2 s . c o m*/ ByteArrayOutputStream baos = closer.register(new ByteArrayOutputStream()); DataOutputStream w = closer.register(new DataOutputStream(baos)); if (val.length() > MAX_INDEXVAL_SIZE) { throw new IOException("KeyFactory - indexValue max 127 chars"); } w.write(INDEXVAL_STRING); //string w.write(val.getBytes("UTF8")); w.write(STRING_END); //stop w.flush(); return baos.toByteArray(); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
From source file:org.apache.jackrabbit.oak.run.SegmentUtils.java
static void backup(File source, File target) throws IOException { Closer closer = Closer.create(); try {//from ww w . j ava2 s .co m FileStore fs; if (FileStoreBackup.USE_FAKE_BLOBSTORE) { fs = openReadOnlyFileStore(source, newBasicReadOnlyBlobStore()); } else { fs = openReadOnlyFileStore(source); } closer.register(asCloseable(fs)); NodeStore store = SegmentNodeStore.builder(fs).build(); FileStoreBackup.backup(store, target); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
From source file:com.spotify.styx.docker.RoutingDockerRunner.java
@Override public void close() throws IOException { final Closer closer = Closer.create(); dockerRunners.values().forEach(closer::register); closer.close(); }
From source file:org.apache.jackrabbit.oak.run.SegmentTarUtils.java
static void backup(File source, File target) throws IOException { Closer closer = Closer.create(); try {//from w w w. j a v a2 s . c om FileStore fs; if (FileStoreBackup.USE_FAKE_BLOBSTORE) { fs = openReadOnlyFileStore(source, newBasicReadOnlyBlobStore()); } else { fs = openReadOnlyFileStore(source); } closer.register(fs); FileStoreBackup.backup(fs.getReader(), fs.getRevisions(), target); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
From source file:com.android.builder.internal.packaging.zip.ProcessedAndRawByteSources.java
@Override public void close() throws IOException { Closer closer = Closer.create(); closer.register(mProcessedSource);/*from w ww. ja v a2 s . c o m*/ closer.register(mRawSource); closer.close(); }