List of usage examples for com.google.common.io InputSupplier getInput
T getInput() throws IOException;
From source file:com.facebook.swift.parser.ThriftIdlParser.java
static Tree parseTree(InputSupplier<? extends Reader> input) throws IOException { try (Reader reader = input.getInput()) { ThriftLexer lexer = new ThriftLexer(new ANTLRReaderStream(reader)); ThriftParser parser = new ThriftParser(new CommonTokenStream(lexer)); try {/*from www .j a v a2 s . c o m*/ Tree tree = (Tree) parser.document().getTree(); if (parser.getNumberOfSyntaxErrors() > 0) { throw new IllegalArgumentException("syntax error"); } return tree; } catch (RecognitionException e) { throw new IllegalArgumentException(e); } } }
From source file:ec.tstoolkit.utilities.XmlReaders.java
@Deprecated public static void parse(XMLReader xmlReader, InputSupplier<? extends InputStream> supplier) throws IOException { try (InputStream stream = supplier.getInput()) { parse(xmlReader, stream);//ww w . j a v a 2 s . c om } }
From source file:org.apache.twill.internal.json.ArgumentsCodec.java
public static Arguments decode(InputSupplier<? extends Reader> readerSupplier) throws IOException { try (Reader reader = readerSupplier.getInput()) { return GSON.fromJson(reader, Arguments.class); }//from w ww. j a v a 2 s . c o m }
From source file:com.continuuity.weave.internal.json.ArgumentsCodec.java
public static Arguments decode(InputSupplier<? extends Reader> readerSupplier) throws IOException { Reader reader = readerSupplier.getInput(); try {/*from w w w . ja v a 2 s .c o m*/ return GSON.fromJson(reader, Arguments.class); } finally { reader.close(); } }
From source file:org.apache.twill.internal.json.JvmOptionsCodec.java
public static JvmOptions decode(InputSupplier<? extends Reader> readerSupplier) throws IOException { try (Reader reader = readerSupplier.getInput()) { return GSON.fromJson(reader, JvmOptions.class); }//from w w w .j a v a 2s. c o m }
From source file:org.sonar.batch.repository.user.UserRepository.java
private static Collection<BatchInput.User> parseUsers(InputSupplier<InputStream> input) { List<BatchInput.User> users = new ArrayList<>(); try (InputStream is = input.getInput()) { BatchInput.User user = BatchInput.User.parseDelimitedFrom(is); while (user != null) { users.add(user);//from w w w .j ava2 s . co m user = BatchInput.User.parseDelimitedFrom(is); } } catch (IOException e) { throw new IllegalStateException("Unable to get user details from server", e); } return users; }
From source file:cc.recommenders.utils.Zips.java
public static void unzip(File source, File dest) throws IOException { ZipInputStream zis = null;/* ww w .java2s. co m*/ 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:edu.cmu.cs.lti.ark.util.SerializedObjects.java
@SuppressWarnings("unchecked") public static <T> T readObject(InputSupplier<ObjectInputStream> inputSupplier) throws IOException, ClassNotFoundException { final ObjectInputStream input = inputSupplier.getInput(); try {// w ww.j a v a 2s. co m return (T) input.readObject(); } finally { closeQuietly(input); } }
From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Json.java
public static <T> List<T> deserializeZip(File zip, Class<T> classOfT) throws IOException { List<T> res = Lists.newLinkedList(); ZipInputStream zis = null;/* w w w .j a v a 2 s . c o m*/ try { InputSupplier<FileInputStream> fis = Files.newInputStreamSupplier(zip); zis = new ZipInputStream(fis.getInput()); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (!entry.isDirectory()) { res.add(Json.<T>deserialize(zis, classOfT)); } } } finally { Closeables.close(zis, true); } return res; }
From source file:org.apache.drill.plan.ParsePlan.java
public static Plan parse(InputSupplier<InputStreamReader> in) throws ParseException { PlanParser r;/*from w w w . j av a 2s . c om*/ try { InputStreamReader inStream = in.getInput(); PlanLexer lex = new PlanLexer(new ANTLRReaderStream(inStream)); r = new PlanParser(new CommonTokenStream(lex)); inStream.close(); } catch (IOException e) { throw new ParseException(e); } try { Plan plan = r.plan().r; validate(plan); return plan; } catch (RecognitionException e) { throw new ParseException(e); } }