Package com.google.common.io

Examples of com.google.common.io.CharSink


         f.deleteOnExit();
         long length = (long) (Runtime.getRuntime().freeMemory() * 1.1);
        
         MessageDigest digester = md5Digest();

         CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
         Writer out = null;
         try {
            out = fileSink.openStream();
            for (long i = 0; i < length; i++) {
               out.append('a');
               digester.update((byte) 'a');
            }
            out.flush();
View Full Code Here


         f.deleteOnExit();
         long length = (new Random().nextInt(32) + 1) * 1024 * 1024;

         MessageDigest digester = md5Digest();

         CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
         Writer out = null;
         try {
            out = fileSink.openStream();
            for (long i = 0; i < length; i++) {
               out.append('a');
               digester.update((byte) 'a');
            }
            out.flush();
View Full Code Here

    String directoryId = "0B1fV80wEwsDzalN6Z3VWNVNFSkU"; // folder

    GDirectory directory = drive.directory(directoryId);

    File file = new File("write");
    CharSink charSink = Files.asCharSink(file, Charsets.UTF_8);
    CharSource
        .wrap("write")
        .copyTo(charSink);

    GFile res = directory.write(file);
View Full Code Here

         f.deleteOnExit();
         long length = (long) (Runtime.getRuntime().freeMemory() * 1.1);
        
         MessageDigest digester = md5Digest();

         CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
         Writer out = null;
         try {
            out = fileSink.openStream();
            for (long i = 0; i < length; i++) {
               out.append('a');
               digester.update((byte) 'a');
            }
            out.flush();
View Full Code Here

         f.deleteOnExit();
         long length = (long) (Runtime.getRuntime().freeMemory() * 1.1);
        
         MessageDigest digester = md5Digest();

         CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
         Writer out = null;
         try {
            out = fileSink.openStream();
            for (long i = 0; i < length; i++) {
               out.append('a');
               digester.update((byte) 'a');
            }
            out.flush();
View Full Code Here

  @Override
  public void setOuter(JUnit4 task) {
    if (outputFile != null) {
      try {
        Files.createParentDirs(outputFile);
        final CharSink charSink;
        if (append) {
          charSink = Files.asCharSink(outputFile, Charsets.UTF_8, FileWriteMode.APPEND);
        } else {
          charSink = Files.asCharSink(outputFile, Charsets.UTF_8);
        }
        this.output = charSink.openBufferedStream();
      } catch (IOException e) {
        throw new BuildException(e);
      }
    } else {
      if (!UNICODE_ENCODINGS.contains(Charset.defaultCharset().name())) {
View Full Code Here

    public void givenUsingGuava_whenWritingReaderContentsToFile_thenCorrect() throws IOException {
        final Reader initialReader = new StringReader("Some text");

        final File targetFile = new File("src/test/resources/targetFile.txt");
        com.google.common.io.Files.touch(targetFile);
        final CharSink charSink = com.google.common.io.Files.asCharSink(targetFile, Charset.defaultCharset(), FileWriteMode.APPEND);
        charSink.writeFrom(initialReader);
        initialReader.close();
    }
View Full Code Here

    public void givenUsingGuava_whenConvertingByteArrayIntoWriter_thenCorrect() throws IOException {
        final byte[] initialArray = "With Guava".getBytes();

        final String buffer = new String(initialArray);
        final StringWriter stringWriter = new StringWriter();
        final CharSink charSink = new CharSink() {
            @Override
            public final Writer openStream() throws IOException {
                return stringWriter;
            }
        };
        charSink.write(buffer);

        stringWriter.close();
    }
View Full Code Here

    @Test
    public void whenWriteUsingCharSink_thenWritten() throws IOException {
        final String expectedValue = "Hello world";
        final File file = new File("src/test/resources/test.out");
        final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);

        sink.write(expectedValue);

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

    @Test
    public void whenWriteMultipleLinesUsingCharSink_thenWritten() throws IOException {
        final List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom");
        final File file = new File("src/test/resources/test.out");
        final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);

        sink.writeLines(names, " ");

        final String result = Files.toString(file, Charsets.UTF_8);
        final String expectedValue = Joiner.on(" ").join(names);
        assertEquals(expectedValue, result.trim());
View Full Code Here

TOP

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

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.