Package com.google.common.io

Examples of com.google.common.io.CharSource


  private Object eval(Reader reader, Context context) throws ScriptException {
    SEXP source;
    try {
      // terminate with '\n'
      CharSource terminated = CharSource.concat(
          newReaderSupplier(reader),
         CharSource.wrap("\n"));
      source = RParser.parseSource(terminated);
    } catch (IOException e) {
      throw new ScriptException(e);
View Full Code Here


    eval(reader);
    reader.close();
  }
 
  private CharSource newReaderSupplier(final Reader reader) {
    return new CharSource() {
      @Override
      public Reader openStream() throws IOException {
        return reader;
      }     
    };
View Full Code Here

    }

    private Optional<Style> tryLoadSLD(final ByteSource byteSource, final Integer styleIndex) throws IOException {
        Assert.isTrue(styleIndex == null || styleIndex > -1, "styleIndex must be > -1 but was: " + styleIndex);

        final CharSource charSource = byteSource.asCharSource(Constants.DEFAULT_CHARSET);
        BufferedReader reader = null;
        final Style[] styles;
        try {
            reader = charSource.openBufferedStream();

            final SLDParser sldParser = new SLDParser(CommonFactoryFinder.getStyleFactory());
            sldParser.setInput(reader);
            styles = sldParser.readXML();
View Full Code Here

        final String geojsonString;
        Closer closer = Closer.create();
        try {
            Reader input;
            if (url.getProtocol().equalsIgnoreCase("file")) {
                final CharSource charSource = Files.asCharSource(new File(url.getFile()), Constants.DEFAULT_CHARSET);
                input = closer.register(charSource.openBufferedStream());
            } else {
                final ClientHttpResponse response = closer.register(this.httpRequestFactory.createRequest(url.toURI(),
                        HttpMethod.GET).execute());

                input = closer.register(new BufferedReader(new InputStreamReader(response.getBody(), Constants.DEFAULT_CHARSET)));
View Full Code Here

    }

    public static List<String> runAndParseCommand(boolean failFast, String... command)
            throws Exception {
        runCommand(failFast, command);
        CharSource reader = CharSource.wrap(stdOut.toString(Charsets.UTF_8.name()));
        ImmutableList<String> lines = reader.readLines();
        return lines;
    }
View Full Code Here

    }

    private StringBuilder getLimitedOutput(FileBackedOutputStream out, final int limit)
            throws IOException {

        CharSource charSource = out.asByteSource().asCharSource(Charsets.UTF_8);
        BufferedReader reader = charSource.openBufferedStream();
        final StringBuilder output = new StringBuilder();
        int count = 0;
        String line;
        while ((line = reader.readLine()) != null) {
            output.append(line).append('\n');
View Full Code Here

    try {
      NetHttpTransport httpTransport = new NetHttpTransport();
      JsonFactory jsonFactory = new JacksonFactory();

      URL url = Resources.getResource(GDrive.class, CLIENTSECRETS_LOCATION);
      CharSource charSource = Resources.asCharSource(url, Charsets.UTF_8);
      Reader reader = charSource.openStream();
      GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, reader);

      GoogleCredential credential = new GoogleCredential.Builder()
          .setTransport(httpTransport)
          .setJsonFactory(jsonFactory)
View Full Code Here

    @Test
    public void whenReadUsingCharSource_thenRead() throws IOException {
        final String expectedValue = "Hello world";
        final File file = new File("src/test/resources/test1.in");

        final CharSource source = Files.asCharSource(file, Charsets.UTF_8);

        final String result = source.read();
        assertEquals(expectedValue, result);
    }
View Full Code Here

    public void whenReadMultipleCharSources_thenRead() throws IOException {
        final String expectedValue = "Hello worldTest";
        final File file1 = new File("src/test/resources/test1.in");
        final File file2 = new File("src/test/resources/test1_1.in");

        final CharSource source1 = Files.asCharSource(file1, Charsets.UTF_8);
        final CharSource source2 = Files.asCharSource(file2, Charsets.UTF_8);
        final CharSource source = CharSource.concat(source1, source2);

        final String result = source.read();

        assertEquals(expectedValue, result);
    }
View Full Code Here

    try {
      NetHttpTransport httpTransport = new NetHttpTransport();
      JsonFactory jsonFactory = new JacksonFactory();

      URL url = Resources.getResource(GDrive.class, CLIENTSECRETS_LOCATION);
      CharSource charSource = Resources.asCharSource(url, Charsets.UTF_8);
      Reader reader = charSource.openStream();
      GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, reader);

      GoogleCredential credential = new GoogleCredential.Builder()
          .setTransport(httpTransport)
          .setJsonFactory(jsonFactory)
View Full Code Here

TOP

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

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.