List of usage examples for com.google.common.io CharStreams readLines
public static List<String> readLines(Readable r) throws IOException
From source file:local.laer.app.newgenerator.ContentGenerator.java
protected static String[] initLoremIspum() { try {/*from w w w . j av a2 s . c om*/ try (InputStream in = ContentGenerator.class.getResourceAsStream("/LoremIspum.txt")) { return CharStreams.readLines(new InputStreamReader(in)).toArray(new String[0]); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.eclipse.che.plugin.docker.client.DockerfileParser.java
/** Parse content of Dockerfile from the specified File. */ public static Dockerfile parse(File file) throws DockerFileException { try {/*from w ww. j a v a2s . co m*/ return parse(CharStreams.readLines(Files.newReader(file, Charset.defaultCharset()))); } catch (IOException e) { throw new DockerFileException("Error happened parsing the Docker file." + e.getMessage(), e); } }
From source file:com.attribyte.essem.model.DisplayTZ.java
/** * Parse a file of the format [id] = [name]. * @param file The file to parse./*from w w w .ja va 2 s.com*/ * @return The list of display zones. * @throws IOException on parse error. */ public static final List<DisplayTZ> parse(final File file) throws IOException { List<String> lines = CharStreams.readLines(new FileReader(file)); List<DisplayTZ> tzList = Lists.newArrayListWithExpectedSize(lines.size()); for (String line : lines) { line = line.trim(); if (line.length() > 0 && !line.startsWith("#")) { Iterator<String> iter = eqSplitter.split(line).iterator(); if (iter.hasNext()) { String id = iter.next(); if (iter.hasNext()) { String display = iter.next(); tzList.add(new DisplayTZ(id, display)); } } } } return tzList; }
From source file:org.eclipse.che.plugin.docker.client.DockerfileParser.java
/** Parse content of Dockerfile from the specified URL. */ public static Dockerfile parse(final URL file) throws DockerFileException { try {//from www.j a v a2s. co m return parse( CharStreams.readLines(Resources.asCharSource(file, Charset.defaultCharset()).openStream())); } catch (IOException e) { throw new DockerFileException("Error happened parsing the Docker file:" + e.getMessage(), e); } }
From source file:org.whispersystems.claserver.UrlFetcher.java
public static String post(String urlString, Object data, Map<String, String> headers) throws IOException { URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true);/*from ww w . j a va2s. c o m*/ connection.addRequestProperty("Content-Type", "application/json"); connection.setRequestMethod("POST"); for (Map.Entry<String, String> header : headers.entrySet()) { connection.setRequestProperty(header.getKey(), header.getValue()); } OutputStream outputStream = connection.getOutputStream(); mapper.writeValue(outputStream, data); outputStream.close(); logger.info(String.format("Status update response: %s", connection.getResponseCode())); return CharStreams.readLines(new InputStreamReader(connection.getInputStream())).get(0); }
From source file:org.kurento.test.monitor.StatsOperation.java
public static Map<String, StatsOperation> map(String csvFile) { if (statsOperationMap == null) { statsOperationMap = new HashMap<>(); InputStream inputStream = StatsOperation.class.getClassLoader().getResourceAsStream(csvFile); try {/* w w w.j a va 2 s. c o m*/ List<String> csv = CharStreams.readLines(new InputStreamReader(inputStream, Charsets.UTF_8)); for (String line : csv) { String[] values = line.split(CSV_FILE_SEPARATOR); statsOperationMap.put(values[1] + "_" + values[0], StatsOperation.getType(values[2])); } } catch (Exception e) { throw new RuntimeException(e); } } return statsOperationMap; }
From source file:org.eclipse.che.plugin.docker.client.DockerfileParser.java
/** Parse content of Dockerfile from the specified Reader. */ public static Dockerfile parse(Reader reader) throws DockerFileException { try {//from w ww . j a v a 2s .c om return parse(CharStreams.readLines(reader)); } catch (IOException e) { throw new DockerFileException("Error happened parsing the Docker file:" + e.getMessage(), e); } }
From source file:org.terasology.assets.test.stubs.text.TextDeltaFileFormat.java
@Override public void apply(AssetDataFile input, TextData assetData) throws IOException { try (InputStreamReader reader = new InputStreamReader(input.openStream(), Charsets.UTF_8)) { for (String line : CharStreams.readLines(reader)) { String[] parts = line.split("->", 2); if (parts.length == 2) { assetData.setValue(assetData.getValue().replace(parts[0], parts[1])); }/*from ww w. ja v a 2 s . c om*/ } } }
From source file:org.locationtech.geogig.plumbing.merge.ReadMergeCommitMessageOp.java
@Override protected String _call() { BlobStore blobStore = context.blobStore(); Optional<InputStream> blobAsStream = blobStore.getBlobAsStream(MergeOp.MERGE_MSG); if (!blobAsStream.isPresent()) { return ""; }/* www. ja v a 2 s .c o m*/ try (InputStream in = blobAsStream.get()) { List<String> lines = CharStreams.readLines(new InputStreamReader(in, Charsets.UTF_8)); return Joiner.on("\n").join(lines); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.terasology.assets.test.stubs.text.TextMetadataFileFormat.java
@Override public void apply(AssetDataFile input, TextData assetData) throws IOException { try (InputStreamReader reader = new InputStreamReader(input.openStream(), Charsets.UTF_8)) { String metadata = Joiner.on("/n").join(CharStreams.readLines(reader)); assetData.setMetadata(metadata); }//from www.j av a 2s . com }