List of usage examples for com.google.common.io InputSupplier InputSupplier
InputSupplier
From source file:com.metamx.druid.guava.GuavaUtils.java
public static InputSupplier<BufferedReader> joinFiles(final List<File> files) { return new InputSupplier<BufferedReader>() { @Override//from w ww. jav a 2 s. c o m public BufferedReader getInput() throws IOException { return new BufferedReader(CharStreams .join(Iterables.transform(files, new Function<File, InputSupplier<InputStreamReader>>() { @Override public InputSupplier<InputStreamReader> apply(final File input) { return new InputSupplier<InputStreamReader>() { @Override public InputStreamReader getInput() throws IOException { InputStream baseStream = new FileInputStream(input); if (input.getName().endsWith(".gz")) { baseStream = new GZIPInputStream(baseStream); } return new InputStreamReader(baseStream, Charsets.UTF_8); } }; } })).getInput()); } }; }
From source file:com.complexible.common.io.IOSuppliers.java
/** * Return an {@link InputSupplier} which is an adapter to the provided {@link Supplier} which provides the actual input * * @param theObj the supplier to provide the input * @param <T> the input type * @return a new InputSupplier/* w ww . ja va 2s. c o m*/ */ public static <T> InputSupplier<T> inputOf(final Supplier<T> theObj) { return new InputSupplier<T>() { @Override public T getInput() throws IOException { return theObj.get(); } }; }
From source file:de.dennishoersch.web.css.CmdLineUtil.java
private static InputSupplier<InputStream> newInputStreamSupplier(final InputStream inputStream) { return new InputSupplier<InputStream>() { @Override// w w w . j a v a2s . c om public InputStream getInput() throws IOException { return inputStream; } }; }
From source file:co.cask.cdap.internal.app.runtime.webapp.JarExploder.java
public static int explode(File jarFile, File destDir, Predicate<JarEntry> filter) throws IOException { int count = 0; try (JarFile jar = new JarFile(jarFile)) { if (!DirUtils.mkdirs(destDir)) { throw new IOException(String.format("Cannot create destination dir %s", destDir.getAbsolutePath())); }/*from w ww .jav a 2s .co m*/ Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (!filter.apply(entry)) { continue; } File file = new File(destDir, entry.getName()); if (entry.isDirectory()) { // Create dir if (!DirUtils.mkdirs(file)) { throw new IOException(String.format("Cannot create dir %s", file.getAbsolutePath())); } continue; } File parentFile = file.getParentFile(); if (!DirUtils.mkdirs(parentFile)) { throw new IOException(String.format("Cannot create dir %s", parentFile)); } // Write file Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return jar.getInputStream(entry); } }, file); ++count; } return count; } }
From source file:edu.cmu.cs.lti.ark.util.SerializedObjects.java
public static <T> T readObject(final String inputFile) throws IOException, ClassNotFoundException { return SerializedObjects.<T>readObject(new InputSupplier<ObjectInputStream>() { @Override/*from www .j a va2 s .co m*/ public ObjectInputStream getInput() throws IOException { return getObjectInputStream(inputFile); } }); }
From source file:uk.ac.cam.arb33.lectureserver.HtmlRenderer.java
HtmlRenderer(final InputStream templateStream) { SoyFileSet sfs = new SoyFileSet.Builder().add(new InputSupplier<InputStreamReader>() { public InputStreamReader getInput() throws IOException { return new InputStreamReader(templateStream); }/* w w w . j a va 2s . co m*/ }, "Interal war resource: " + templateStream).build(); tofu = sfs.compileToTofu().forNamespace("uk.ac.cam.arb33.lectureserver.soy"); }
From source file:org.jclouds.io.CopyInputStreamIntoSupplier.java
@SuppressWarnings("unchecked") @Override//ww w .j av a 2s . co m public InputSupplier<InputStream> apply(InputStream from) { if (from == null) return new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return null; } }; try { return InputSupplier.class.cast(ByteStreams.newInputStreamSupplier(ByteStreams.toByteArray(from))); } catch (Exception e) { logger.warn(e, "ignoring problem retrieving credentials"); return null; } finally { Closeables.closeQuietly(from); } }
From source file:co.cask.tigon.io.Locations.java
/** * Creates a new {@link com.google.common.io.InputSupplier} that can provides {@link SeekableInputStream} from * the given location.//from w w w.j a v a2s. com * * @param location Location for the input stream. * @return A {@link com.google.common.io.InputSupplier}. */ public static InputSupplier<? extends SeekableInputStream> newInputSupplier(final Location location) { return new InputSupplier<SeekableInputStream>() { @Override public SeekableInputStream getInput() throws IOException { return SeekableInputStream.create(location.getInputStream()); } }; }
From source file:com.xebialabs.overthere.util.OverthereUtils.java
/** * Reads the contents of an {@link OverthereFile} into a string. * * @param from the file to read from. * @param charsetName the {@link java.nio.charset.Charset charset} to use. * @returns the string./*from w w w .j a v a 2 s .c o m*/ */ public static String read(final OverthereFile from, final String charsetName) { try { return CharStreams.toString(new InputSupplier<Reader>() { @Override public Reader getInput() throws IOException { return new InputStreamReader(from.getInputStream(), charsetName); } }); } catch (IOException exc) { throw new RuntimeException(exc); } }
From source file:net.seedboxer.core.util.FileUtils.java
public static File copyFile(final InputStream in, String finalPath, boolean readPermissions, boolean writePermissions) throws IOException { File copyFile = new File(finalPath); Files.copy(new InputSupplier<InputStream>() { @Override/*w w w .j a va 2s . c o m*/ public InputStream getInput() throws IOException { return in; } }, copyFile); if (readPermissions) { copyFile.setReadable(true, false); } if (writePermissions) { copyFile.setWritable(true, false); } return copyFile; }