Java 类com.google.common.io.InputSupplier 实例源码

项目:QDrill    文件:FunctionConverter.java   
private String getClassBody(Class<?> c) throws CompileException, IOException{
  String path = c.getName();
  path = path.replaceFirst("\\$.*", "");
  path = path.replace(".", FileUtils.separator);
  path = "/" + path + ".java";
  URL u = Resources.getResource(c, path);
  InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
  try (InputStream is = supplier.getInput()) {
    if (is == null) {
      throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
    }
    String body = IO.toString(is);

    //TODO: Hack to remove annotations so Janino doesn't choke.  Need to reconsider this problem...
    //return body.replaceAll("@(?:Output|Param|Workspace|Override|SuppressWarnings\\([^\\\\]*?\\)|FunctionTemplate\\([^\\\\]*?\\))", "");
    return body.replaceAll("@(?:\\([^\\\\]*?\\))?", "");
  }

}
项目:appinventor-extensions    文件:ProjectBuilder.java   
private ArrayList<String> extractProjectFiles(ZipFile inputZip, File projectRoot)
    throws IOException {
  ArrayList<String> projectFileNames = Lists.newArrayList();
  Enumeration<? extends ZipEntry> inputZipEnumeration = inputZip.entries();
  while (inputZipEnumeration.hasMoreElements()) {
    ZipEntry zipEntry = inputZipEnumeration.nextElement();
    final InputStream extractedInputStream = inputZip.getInputStream(zipEntry);
    File extractedFile = new File(projectRoot, zipEntry.getName());
    LOG.info("extracting " + extractedFile.getAbsolutePath() + " from input zip");
    Files.createParentDirs(extractedFile); // Do I need this?
    Files.copy(
        new InputSupplier<InputStream>() {
          public InputStream getInput() throws IOException {
            return extractedInputStream;
          }
        },
        extractedFile);
    projectFileNames.add(extractedFile.getPath());
  }
  return projectFileNames;
}
项目:emodb    文件:CasBlobStoreTest.java   
private void verifyPutAndGet(String blobId, final byte[] blobData, Map<String, String> attributes, @Nullable Duration ttl)
        throws IOException {
    _store.put(TABLE, blobId, new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
            return new ByteArrayInputStream(blobData);
        }
    }, attributes, ttl);

    // verify that we can get what we put
    Blob blob = _store.get(TABLE, blobId);
    assertEquals(blob.getId(), blobId);
    assertEquals(blob.getLength(), blobData.length);
    assertEquals(blob.getAttributes(), attributes);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    blob.writeTo(buf);
    assertEquals(buf.toByteArray(), blobData);

    BlobMetadata md = _store.getMetadata(TABLE, blobId);
    assertEquals(md.getId(), blobId);
    assertEquals(md.getLength(), blobData.length);
    assertEquals(md.getAttributes(), attributes);
}
项目:Camel    文件:JcloudsPayloadConverter.java   
@Converter
public static Payload toPayload(final InputStream is, Exchange exchange) throws IOException {
    InputStreamPayload payload = new InputStreamPayload(is);
    // only set the contentlength if possible
    if (is.markSupported()) {
        long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {
            @Override
            public InputStream getInput() throws IOException {
                return is;
            }
        });
        is.reset();
        payload.getContentMetadata().setContentLength(contentLength);
    }
    return payload;
}
项目:PlotSquared-Chinese    文件:NbtFactory.java   
/**
 * Load the content of a file from a stream.
 * <p>
 * Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
 * @param stream - the stream supplier.
 * @param option - whether or not to decompress the input stream.
 * @return The decoded NBT compound.
 * @throws IOException If anything went wrong.
 */
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
    InputStream input = null;
    DataInputStream data = null;
    boolean suppress = true;

    try {
        input = stream.getInput();
        data = new DataInputStream(new BufferedInputStream(
            option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
        ));

        NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
        suppress = false;
        return result;

    } finally {
        if (data != null)
            Closeables.close(data, suppress);
        else if (input != null)
            Closeables.close(input, suppress);
    }
}
项目:MineFantasy    文件:BattlegearTranslator.java   
public static void setup(String deobFileName){
    try{
        LZMAInputSupplier zis = new LZMAInputSupplier(FMLInjectionData.class.getResourceAsStream(deobFileName));
        InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8);
        List<String> srgList = CharStreams.readLines(srgSupplier);

        for (String line : srgList) {

            line = line.replace(" #C", "").replace(" #S", "");

            if (line.startsWith("CL")) {
                parseClass(line);
            } else if (line.startsWith("FD")) {
                parseField(line);
            } else if (line.startsWith("MD")) {
                parseMethod(line);
            }

        }


    }catch(Exception e){
        e.printStackTrace();
    }
}
项目:java-util-examples    文件:ReadPropertiesFile.java   
@Test
public void read_properties_file_guava() throws IOException {

    URL url = Resources.getResource(PROPERTY_FILE_NAME);
    InputSupplier<InputStream> inputSupplier = 
            Resources.newInputStreamSupplier(url);

    Properties properties = new Properties();
    properties.load(inputSupplier.getInput());

    logger.info(properties);

    assertEquals("http://www.leveluplunch.com", properties.getProperty("website"));
    assertEquals("English", properties.getProperty("language"));
    assertEquals("Welcome up to leveluplunch.com", properties.getProperty("message"));
}
项目:distributeTemplate    文件:FileSystemService.java   
/**
 * 将文件打包成消息协议
 * @param file
 * @return
 * 添加(修改)人:zhuyuping
 * @throws Exception 
 * @throws FileNotFoundException 
 */
   private FileDataMessage wrapFile(File file){
    FileDataMessage fm=new FileDataMessage();
    try{
    final InputStream input=new FileInputStream(file);
    fm.setBytes(ByteStreams.toByteArray(input));
    fm.setSessionId(System.identityHashCode(file.getAbsolutePath()));
    fm.setHead(1314);
    fm.setCommand(1);
    fm.setLenth(file.length());
    fm.setPath(file.getAbsolutePath());
    fm.setStart(0);
    fm.setEnd(file.length());
    fm.setHash(ByteStreams.getChecksum(new InputSupplier<InputStream>() {

        @Override
        public InputStream getInput() throws IOException {

            return input;
        }
    }, new Adler32()));//crc32最强验证 adl32最弱验证
    }catch(Exception e){

    }
    return fm;
}
项目:incubator-twill    文件:JvmOptionsCodecTest.java   
@Test
public void testNoNulls() throws Exception {
  JvmOptions options = new JvmOptions("-version",
                                      new JvmOptions.DebugOptions(true, false, ImmutableSet.of("one", "two")));
  final StringWriter writer = new StringWriter();
  JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return writer;
    }
  });
  JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
    @Override
    public Reader getInput() throws IOException {
      return new StringReader(writer.toString());
    }
  });
  Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
  Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
  Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
  Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
项目:incubator-twill    文件:JvmOptionsCodecTest.java   
@Test
public void testSomeNulls() throws Exception {
  JvmOptions options = new JvmOptions(null, new JvmOptions.DebugOptions(false, false, null));
  final StringWriter writer = new StringWriter();
  JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return writer;
    }
  });
  JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
    @Override
    public Reader getInput() throws IOException {
      return new StringReader(writer.toString());
    }
  });
  Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
  Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
  Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
  Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
项目:incubator-twill    文件:JvmOptionsCodecTest.java   
@Test
public void testNoRunnables() throws Exception {
  List<String> noRunnables = Collections.emptyList();
  JvmOptions options = new JvmOptions(null, new JvmOptions.DebugOptions(true, false, noRunnables));
  final StringWriter writer = new StringWriter();
  JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
    @Override
    public Writer getOutput() throws IOException {
      return writer;
    }
  });
  JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
    @Override
    public Reader getInput() throws IOException {
      return new StringReader(writer.toString());
    }
  });
  Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
  Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
  Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
  Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
项目:Crafty    文件:NbtFactory.java   
/**
 * Load the content of a file from a stream.
 * <p>
 * Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
 * @param stream - the stream supplier.
 * @param option - whether or not to decompress the input stream.
 * @return The decoded NBT compound.
 * @throws IOException If anything went wrong.
 */
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
    InputStream input = null;
    DataInputStream data = null;
    boolean suppress = true;

    try {
        input = stream.getInput();
        data = new DataInputStream(new BufferedInputStream(
                option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
        ));

        NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
        suppress = false;
        return result;

    } finally {
        if (data != null)
            Closeables.close(data, suppress);
        else if (input != null)
            Closeables.close(input, suppress);
    }
}
项目:KingKits    文件:NbtFactory.java   
/**
 * Load the content of a file from a stream.
 * <p>
 * Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
 *
 * @param stream - the stream supplier.
 * @param option - whether or not to decompress the input stream.
 * @return The decoded NBT compound.
 * @throws IOException If anything went wrong.
 */
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
    InputStream input = null;
    DataInputStream data = null;
    boolean suppress = true;

    try {
        input = stream.getInput();
        data = new DataInputStream(new BufferedInputStream(
                option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
        ));

        NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
        suppress = false;
        return result;

    } finally {
        if (data != null)
            Closeables.close(data, suppress);
        else if (input != null)
            Closeables.close(input, suppress);
    }
}
项目:jclouds-examples    文件:HdfsPayloadSlicer.java   
protected Payload doSlice(final FSDataInputStream inputStream,
      final long offset, final long length) {
   return new InputStreamSupplierPayload(new InputSupplier<InputStream>() {
      public InputStream getInput() throws IOException {
         if (offset > 0) {
            try {
               inputStream.seek(offset);
            } catch (IOException e) {
               Closeables.closeQuietly(inputStream);
               throw e;
            }
         }
         return new LimitInputStream(inputStream, length);
      }
   });
}
项目:renjin-statet    文件:LazyLoadFrame.java   
public LazyLoadFrame(Context context, InputSupplier<? extends InputStream> frame) throws IOException {
  this.context = context;

  DataInputStream din = new DataInputStream(frame.getInput());
  int version = din.readInt();
  if(version != VERSION) {
    throw new IOException("Unsupported version: " + version);
  }
  int count = din.readInt();
  for(int i=0;i!=count;++i) {
    String name = din.readUTF();
    int byteCount = din.readInt();
    byte[] bytes = new byte[byteCount];
    din.readFully(bytes);
    map.put(Symbol.get(name), new Value(bytes));
  }
  din.close();
}
项目:cub    文件:AndroidStringsTest.java   
public void testWriteToStrings() throws Exception {
  URL stringsUrl = Resources.getResource(AndroidStringsTest.class, "strings.xml");
  InputSupplier<InputStream> inputSupplier = Resources.newInputStreamSupplier(stringsUrl);
  MessageCatalog messageCatalog = new AndroidStrings();
  ReadableMessageCatalog readableCatalog = messageCatalog.readFrom(inputSupplier.getInput());
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  WritableMessageCatalog writableCatalog = messageCatalog.writeTo(outputStream);

  for (Message message : readableCatalog.readMessages()) {
    writableCatalog.writeMessage(message);
  }

  writableCatalog.close();

  String content = new String(outputStream.toByteArray(), Charsets.UTF_8);
  String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  + "<resources>\n"
  + "  <string name=\"hello\">Hello!</string>\n"
  + "</resources>\n";
  Assert.assertEquals(expected, content);
}
项目:fingertree    文件:FingerTreeByteString.java   
@Override
public InputStream newInput() {
    try {
        return ByteStreams.join(Iterables.transform(
                bytes,
                new Function<ByteStringLiteral, InputSupplier<InputStream>>() {
                    @Override
                    public InputSupplier<InputStream> apply(final ByteStringLiteral literal) {
                        return new InputSupplier<InputStream>() {
                            @Override
                            public InputStream getInput() throws IOException {
                                return literal.newInput();
                            }
                        };
                    }
                }
        )).getInput();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
项目:fingertree    文件:ByteString.java   
@Override
public boolean equals(final Object obj) {
    if (obj == null || !(obj instanceof ByteString)) {
        return false;
    }
    try {
        return ByteStreams.equal(
                new InputSupplier<InputStream>() {
                    @Override
                    public InputStream getInput() throws IOException {
                        return newInput();
                    }
                },
                new InputSupplier<InputStream>() {
                    @Override
                    public InputStream getInput() throws IOException {
                        return ((ByteString) obj).newInput();
                    }
                }
        );
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
项目:levelup-java-examples    文件:ReadPropertiesFile.java   
@Test
public void read_properties_file_guava() throws IOException {

    URL url = Resources.getResource(PROPERTY_FILE_NAME);
    InputSupplier<InputStream> inputSupplier = 
            Resources.newInputStreamSupplier(url);

    Properties properties = new Properties();
    properties.load(inputSupplier.getInput());

    logger.info(properties);

    assertEquals("http://www.leveluplunch.com", properties.getProperty("website"));
    assertEquals("English", properties.getProperty("language"));
    assertEquals("Welcome up to leveluplunch.com", properties.getProperty("message"));
}
项目:syringe-maven-plugin    文件:ModuleScannerMojo.java   
private File[] collectJars() throws IOException {
    File classpathFile = new File(outputDirectory, "classpath");
    if (!classpathFile.exists()) {
        return null;
    }

    final FileReader cpFileReader = new FileReader(classpathFile);
    String classpath = CharStreams.readFirstLine(new InputSupplier<FileReader>() {
        @Override
        public FileReader getInput() throws IOException {
            return cpFileReader;
        }
    });

    String[] jars = classpath.split(";");
    File[] jarFiles = new File[jars.length];
    for (int i = 0; i < jars.length; i++) {
        String jar = jars[i];
        jarFiles[i] = new File(jar);
    }

    return jarFiles;
}
项目:mclab    文件:Refactorings.java   
public static <T extends Reader> List<Refactoring>
    fromInputSupplier(InputSupplier<T> supplier) throws IOException{
  return CharStreams.readLines(supplier,  new LineProcessor<List<Refactoring>>() {
    private List<Refactoring> refactorings = Lists.newArrayList();
    private final Splitter SPLITTER = Splitter.on("->").trimResults().omitEmptyStrings();

    @Override
    public List<Refactoring> getResult() {
      return Collections.unmodifiableList(refactorings);
    }

    @Override
    public boolean processLine(String line) {
      Iterator<String> parts = SPLITTER.split(line).iterator();
      String from = parts.next();
      String to = parts.next();
      refactorings.add(Refactoring.of(from, to, Refactoring.Visit.Expressions));
      return true;
    }
  });
}
项目:n4js    文件:JSLibSingleTestConfigProvider.java   
/**
 * @param resourceName
 *            the classpath-relative location of the to-be-read resource
 */
private static List<String> getFileLines(final String resourceName) throws IOException {
    InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(
            new InputSupplier<InputStream>() {
                @Override
                public InputStream getInput() throws IOException {
                    return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
                }
            }, Charsets.UTF_8);
    return CharStreams.readLines(readerSupplier);
}
项目:n4js    文件:TestCodeProvider.java   
/***/
public static String getContentsFromFileEntry(final ZipEntry entry, String rootName) throws IOException,
URISyntaxException {
    URL rootURL = Thread.currentThread().getContextClassLoader().getResource(rootName);
    try (final ZipFile root = new ZipFile(new File(rootURL.toURI()));) {
        InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(
                new InputSupplier<InputStream>() {
                    @Override
                    public InputStream getInput() throws IOException {
                        return root.getInputStream(entry);
                    }
                }, Charsets.UTF_8);
        return CharStreams.toString(readerSupplier);
    }
}
项目:QDrill    文件:FunctionConverter.java   
private CompilationUnit get(Class<?> c) throws IOException{
  String path = c.getName();
  path = path.replaceFirst("\\$.*", "");
  path = path.replace(".", FileUtils.separator);
  path = "/" + path + ".java";
  CompilationUnit cu = functionUnits.get(path);
  if(cu != null) {
    return cu;
  }

  URL u = Resources.getResource(c, path);
  InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
  try (InputStream is = supplier.getInput()) {
    if (is == null) {
      throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
    }
    String body = IO.toString(is);

    //TODO: Hack to remove annotations so Janino doesn't choke.  Need to reconsider this problem...
    body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", "");
    try{
      cu = new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit();
      functionUnits.put(path, cu);
      return cu;
    } catch (CompileException e) {
      logger.warn("Failure while parsing function class:\n{}", body, e);
      return null;
    }

  }

}
项目:workspacemechanic    文件:InMemoryTaskProvider.java   
public long computeMD5() throws IOException {
  InputSupplier<InputStream> supplier = new InputSupplier<InputStream>() {
    public InputStream getInput() throws IOException {
      return newInputStream();
    }
  };
  return ByteStreams.hash(supplier, Hashing.md5()).asLong();
}
项目:workspacemechanic    文件:UriTaskProvider.java   
public long computeMD5() throws IOException {
  InputSupplier<InputStream> supplier = new InputSupplier<InputStream>() {
    public InputStream getInput() throws IOException {
      return newInputStream();
    }
  };
  return ByteStreams.hash(supplier, Hashing.md5()).asLong();
}
项目:emodb    文件:BlobStoreResource1.java   
/**
 * Returns an InputSupplier that throws an exception if the caller attempts to consume the input stream
 * multiple times.
 */
private InputSupplier<InputStream> onceOnlySupplier(final InputStream in) {
    final AtomicBoolean once = new AtomicBoolean();
    return new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
            if (!once.compareAndSet(false, true)) {
                throw new IllegalStateException("Input stream may be consumed only once per BlobStore call.");
            }
            return in;
        }
    };
}
项目:emodb    文件:BlobStoreJerseyTest.java   
@Test
public void testPut() throws IOException {
    InputSupplier<InputStream> in = new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
            return new ByteArrayInputStream("blob-content".getBytes());
        }
    };
    Map<String, String> attributes = ImmutableMap.of("key", "value");
    blobClient().put("table-name", "blob-id", in, attributes, Duration.standardDays(30));

    //noinspection unchecked
    verify(_server).put(eq("table-name"), eq("blob-id"), isA(InputSupplier.class), eq(attributes), eq(Duration.standardDays(30)));
    verifyNoMoreInteractions(_server);
}
项目:emodb    文件:JsonStreamingArrayParserTest.java   
@Test
@SuppressWarnings("unchecked")
public void testMalformedChunkException() throws Exception {
    InputSupplier<InputStream> input = ByteStreams.join(
            ByteStreams.newInputStreamSupplier("[5,6".getBytes(Charsets.UTF_8)),
            exceptionStreamSupplier(new MalformedChunkCodingException("Bad chunk header")));
    assertThrowsEOFException(input.getInput(), Integer.class);
}
项目:emodb    文件:JsonStreamingArrayParserTest.java   
@Test
@SuppressWarnings("unchecked")
public void testTruncatedChunkException() throws Exception {
    InputSupplier<InputStream> input = ByteStreams.join(
            ByteStreams.newInputStreamSupplier("[5,6".getBytes(Charsets.UTF_8)),
            exceptionStreamSupplier(new TruncatedChunkException("Truncated chunk ( expected size: 3996; actual size: 1760)")));
    assertThrowsEOFException(input.getInput(), Integer.class);
}
项目:emodb    文件:JsonStreamingArrayParserTest.java   
private InputSupplier<InputStream> exceptionStreamSupplier(final Throwable t) {
    return new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
            return exceptionStream(t);
        }
    };
}
项目:emodb    文件:BlobStoreClient.java   
@Override
public void put(String apiKey, String table, String blobId, InputSupplier<? extends InputStream> in,
                Map<String, String> attributes, @Nullable Duration ttl)
        throws IOException {
    checkNotNull(table, "table");
    checkNotNull(blobId, "blobId");
    checkNotNull(in, "in");
    checkNotNull(attributes, "attributes");
    try {
        // Encode the ttl as a URL query parameter
        Integer ttlSeconds = Ttls.toSeconds(ttl, 0, null);
        URI uri = _blobStore.clone()
                .segment(table, blobId)
                .queryParam("ttl", (ttlSeconds != null) ? new Object[]{ttlSeconds} : new Object[0])
                .build();
        // Encode the rest of the attributes as request headers
        EmoResource request = _client.resource(uri);
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            request.header(X_BVA_PREFIX + entry.getKey(), entry.getValue());
        }
        // Upload the object
        request.type(MediaType.APPLICATION_OCTET_STREAM_TYPE)
                .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
                .put(in.getInput());
    } catch (EmoClientException e) {
        throw convertException(e);
    }
}
项目:intellij-ce-playground    文件:LauncherGenerator.java   
public void injectIcon(int id, final InputStream iconStream) throws IOException {
  File f = File.createTempFile("launcher", "ico");
  Files.copy(new InputSupplier<InputStream>() {
    @Override
    public InputStream getInput() throws IOException {
      return iconStream;
    }
  }, f);
  IconResourceInjector iconInjector = new IconResourceInjector();
  iconInjector.injectIcon(f, myRoot, "IRD" + id);
}
项目:Camel    文件:JcloudsPayloadConverter.java   
@Converter
public static Payload toPayload(final StreamSourceCache cache, Exchange exchange) throws IOException {
    long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
            return cache.getInputStream();
        }
    });
    cache.reset();
    InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
    payload.getContentMetadata().setContentLength(contentLength);
    setContentMetadata(payload, exchange);
    return payload;
}
项目:greyfish    文件:Persisters.java   
public static <T> T deserialize(final Persister persister, final InputSupplier<? extends InputStream> inputSupplier, final Class<T> clazz) throws IOException, ClassCastException, ClassNotFoundException {
    final InputStream input = inputSupplier.getInput();
    boolean threw = true;
    try {
        final T object = persister.deserialize(input, clazz);
        threw = false;
        return object;
    } finally {
        Closeables.close(input, threw);
    }
}
项目:MyJohnDeereAPI-OAuth-Java-Client    文件:RestRequest.java   
public RestRequest(final String method,
                   final String uri,
                   final OAuthClient client,
                   final OAuthToken token,
                   final InputSupplier<? extends InputStream> body,
                   final HttpHeader... headers) {
    this(method, uri, client, token, body, asList(headers));
}
项目:MyJohnDeereAPI-OAuth-Java-Client    文件:RestRequest.java   
public RestRequest(final String method,
                   final String uri,
                   final OAuthClient client,
                   final OAuthToken token,
                   final InputSupplier<? extends InputStream> body,
                   final List<HttpHeader> headers) {
    this.method = method;
    this.uri = uri;
    this.client = client;
    this.token = token;
    this.headers = headers;
    this.body = body;
}
项目:Pushjet-Android    文件:ApplicationClassesInSystemClassLoaderWorkerFactory.java   
public void prepareJavaCommand(JavaExecSpec execSpec) {
    execSpec.setMain("jarjar." + GradleWorkerMain.class.getName());
    execSpec.classpath(classPathRegistry.getClassPath("WORKER_MAIN").getAsFiles());
    Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
    if (requestedSecurityManager != null) {
        execSpec.systemProperty("org.gradle.security.manager", requestedSecurityManager);
    }
    execSpec.systemProperty("java.security.manager", "jarjar." + BootstrapSecurityManager.class.getName());
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(bytes));
        LOGGER.debug("Writing an application classpath to child process' standard input.");
        outstr.writeInt(processBuilder.getApplicationClasspath().size());
        for (File file : processBuilder.getApplicationClasspath()) {
            outstr.writeUTF(file.getAbsolutePath());
        }
        outstr.close();
        final InputStream originalStdin = execSpec.getStandardInput();
        InputStream input = ByteStreams.join(ByteStreams.newInputStreamSupplier(bytes.toByteArray()), new InputSupplier<InputStream>() {
            public InputStream getInput() throws IOException {
                return originalStdin;
            }
        }).getInput();
        execSpec.setStandardInput(input);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:Pushjet-Android    文件:ApplicationClassesInSystemClassLoaderWorkerFactory.java   
public void prepareJavaCommand(JavaExecSpec execSpec) {
    execSpec.setMain("jarjar." + GradleWorkerMain.class.getName());
    execSpec.classpath(classPathRegistry.getClassPath("WORKER_MAIN").getAsFiles());
    Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
    if (requestedSecurityManager != null) {
        execSpec.systemProperty("org.gradle.security.manager", requestedSecurityManager);
    }
    execSpec.systemProperty("java.security.manager", "jarjar." + BootstrapSecurityManager.class.getName());
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(bytes));
        LOGGER.debug("Writing an application classpath to child process' standard input.");
        outstr.writeInt(processBuilder.getApplicationClasspath().size());
        for (File file : processBuilder.getApplicationClasspath()) {
            outstr.writeUTF(file.getAbsolutePath());
        }
        outstr.close();
        final InputStream originalStdin = execSpec.getStandardInput();
        InputStream input = ByteStreams.join(ByteStreams.newInputStreamSupplier(bytes.toByteArray()), new InputSupplier<InputStream>() {
            public InputStream getInput() throws IOException {
                return originalStdin;
            }
        }).getInput();
        execSpec.setStandardInput(input);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:multireducers    文件:MultiIT.java   
private void fillMapFromFile(final FileContext fc, FileStatus[] first, Multiset<String> countFirst) throws IOException {
    for (final FileStatus status : first) {
        Multiset<String> map = MultiJobTest.toMap(new InputSupplier<InputStream>() {
            @Override
            public InputStream getInput() throws IOException {
                return fc.open(status.getPath());
            }
        });
        countFirst.addAll(map);
    }
}