Package com.google.common.io

Examples of com.google.common.io.ByteSink


   * @param charset The charset to write in.
   * @throws IOException If there is an exception while writing.
   */
  public static void write(String str, final OutputStream outputStream, Charset charset)
      throws IOException {
    new ByteSink() {
      public OutputStream openStream() {
        return outputStream;
      }
    }.asCharSink(charset).write(str);
  }
View Full Code Here


      throws IOException {
    new ByteSource() {
      public InputStream openStream() {
        return inputStream;
      }
    }.copyTo(new ByteSink() {
      public OutputStream openStream() {
        return outputStream;
      }
    });
  }
View Full Code Here

   * @throws IOException if the steam cannot be written to
   */
  @VisibleForTesting
  static void writeBytesToStream(byte[] bytes, final OutputStream outputStream)
      throws IOException {
    new ByteSink() {
      public OutputStream openStream() {
        return outputStream;
      }
    }.write(bytes);
  }
View Full Code Here

     *
     * @param object the object
     * @throws java.io.IOException on save error
     */
    public static void commit(@NonNull Object object) throws IOException {
        ByteSink sink;
        synchronized (bound) {
            sink = bound.get(object);
            if (sink == null) {
                throw new IOException("Cannot persist unbound object: " + object);
            }
        }

        Closer closer = Closer.create();
        try {
            OutputStream os = closer.register(sink.openBufferedStream());
            mapper.writeValue(os, object);
        } finally {
            closer.close();
        }
    }
View Full Code Here

     * @param <V> the type of class
     * @return an object
     */
    public static <V> V load(File file, Class<V> cls, boolean returnNull) {
        ByteSource source = Files.asByteSource(file);
        ByteSink sink = new MkdirByteSink(Files.asByteSink(file), file.getParentFile());

        Scrambled scrambled = cls.getAnnotation(Scrambled.class);
        if (cls.getAnnotation(Scrambled.class) != null) {
            source = new ScramblingSourceFilter(source, scrambled.value());
            sink = new ScramblingSinkFilter(sink, scrambled.value());
View Full Code Here

    @Test
    public void whenWriteUsingByteSink_thenWritten() throws IOException {
        final String expectedValue = "Hello world";
        final File file = new File("src/test/resources/test.out");
        final ByteSink sink = Files.asByteSink(file);

        sink.write(expectedValue.getBytes());

        final String result = Files.toString(file, Charsets.UTF_8);
        assertEquals(expectedValue, result);
    }
View Full Code Here

        public InputStream openStream() throws IOException {
          return request.getInputStream();
        }
      }.asCharSource(Charsets.UTF_8).read());

      new ByteSink() {
        public OutputStream openStream() {
          return response.getOutputStream();
        }
      }.asCharSink(Charsets.UTF_8).write(mockResponseBodies.get(numInteractions++));
View Full Code Here

TOP

Related Classes of com.google.common.io.ByteSink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.