List of usage examples for com.google.common.io CharStreams readLines
public static List<String> readLines(Readable r) throws IOException
From source file:brooklyn.location.basic.BasicMachineDetails.java
/** * @return A task that gathers machine details by SSHing to the machine and running * a Bash script to gather data. */// w ww . j ava2 s . com static Task<BasicMachineDetails> taskForSshMachineLocation(SshMachineLocation location) { BufferedReader reader = new BufferedReader(Streams.reader(new ResourceUtils(BasicMachineDetails.class) .getResourceFromUrl("classpath://brooklyn/location/basic/os-details.sh"))); List<String> script; try { script = CharStreams.readLines(reader); } catch (IOException e) { LOG.error("Error reading os-details script", e); throw Throwables.propagate(e); } finally { try { reader.close(); } catch (IOException e) { // Not rethrowing e because it might obscure an exception caught by the first catch LOG.error("Error closing os-details script reader", e); } } Task<BasicMachineDetails> task = new PlainSshExecTaskFactory<String>(location, script) .summary("Getting machine details for: " + location).requiringZeroAndReturningStdout() .returning(taskToMachineDetailsFunction(location)).newTask().asTask(); return task; }
From source file:org.renjin.maven.PackageDescription.java
public static PackageDescription fromString(String contents) throws IOException { PackageDescription d = new PackageDescription(); d.properties = ArrayListMultimap.create(); List<String> lines = CharStreams.readLines(new StringReader(contents)); String key = null;//from w ww . ja v a2s. c om StringBuilder value = new StringBuilder(); for (String line : lines) { if (line.length() > 0) { if (Character.isWhitespace(line.codePointAt(0))) { if (key == null) { throw new IllegalArgumentException("Expected key at line '" + line + "'"); } value.append(" ").append(line.trim()); } else { if (key != null) { d.properties.put(key, value.toString()); value.setLength(0); } int colon = line.indexOf(':'); if (colon == -1) { throw new IllegalArgumentException( "Expected line in format key: value, found '" + line + "'"); } key = line.substring(0, colon); value.append(line.substring(colon + 1).trim()); } } } if (key != null) { d.properties.put(key, value.toString()); } return d; }
From source file:org.apache.brooklyn.location.basic.BasicMachineDetails.java
/** * @return A task that gathers machine details by SSHing to the machine and running * a Bash script to gather data. *//*from w ww . j a v a 2s .c o m*/ static Task<BasicMachineDetails> taskForSshMachineLocation(SshMachineLocation location) { BufferedReader reader = new BufferedReader(Streams.reader(new ResourceUtils(BasicMachineDetails.class) .getResourceFromUrl("classpath://org/apache/brooklyn/location/basic/os-details.sh"))); List<String> script; try { script = CharStreams.readLines(reader); } catch (IOException e) { LOG.error("Error reading os-details script", e); throw Throwables.propagate(e); } finally { try { reader.close(); } catch (IOException e) { // Not rethrowing e because it might obscure an exception caught by the first catch LOG.error("Error closing os-details script reader", e); } } Task<BasicMachineDetails> task = new PlainSshExecTaskFactory<String>(location, script) .summary("Getting machine details for: " + location).requiringZeroAndReturningStdout() .returning(taskToMachineDetailsFunction(location)).newTask().asTask(); return task; }
From source file:org.nmdp.ngs.tools.FilterSamples.java
static Set<String> readSampleIds(final File file) throws IOException { BufferedReader reader = null; Set<String> sampleIds = new HashSet<String>(); try {/*from ww w.j a v a 2s.c o m*/ reader = reader(file); sampleIds.addAll(CharStreams.readLines(reader)); } finally { try { reader.close(); } catch (Exception e) { // ignore } } return sampleIds; }
From source file:org.onosproject.ui.impl.lion.LionConfig.java
/** * Loads in the specified file and attempts to parse it as a * {@code .lioncfg} format file./*from w w w .j a v a 2s . co m*/ * * @param source path to .lioncfg file * @return the instance * @throws IllegalArgumentException if there is a problem reading the file */ public LionConfig load(String source) { try (Reader r = new InputStreamReader(getClass().getResourceAsStream(source), UTF_8)) { lines = CharStreams.readLines(r); } catch (IOException e) { throw new IllegalArgumentException("Failed to read: " + source, e); } stripCommentsAndWhitespace(); parse(); processAliases(); processFroms(); return this; }
From source file:com.music.web.util.RequestBlockingFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { InputStream is = filterConfig.getServletContext().getResourceAsStream("/WEB-INF/classes/bots/agents.txt"); InputStreamReader reader = new InputStreamReader(is); try {//from ww w. j a v a 2 s . c om blockedAgents = new HashSet<String>(CharStreams.readLines(reader)); } catch (IOException ex) { throw new IllegalStateException("Failed to load blocked user agents list", ex); } finally { IOUtils.closeQuietly(reader); } }
From source file:org.apache.brooklyn.core.location.BasicMachineDetails.java
/** * @return A task that gathers machine details by SSHing to the machine and running * a Bash script to gather data. *//*ww w . ja v a 2s .c o m*/ public static Task<BasicMachineDetails> taskForSshMachineLocation(SshMachineLocation location) { BufferedReader reader = new BufferedReader(Streams.reader(new ResourceUtils(BasicMachineDetails.class) .getResourceFromUrl("classpath://org/apache/brooklyn/location/basic/os-details.sh"))); List<String> script; try { script = CharStreams.readLines(reader); } catch (IOException e) { LOG.error("Error reading os-details script", e); throw Throwables.propagate(e); } finally { try { reader.close(); } catch (IOException e) { // Not rethrowing e because it might obscure an exception caught by the first catch LOG.error("Error closing os-details script reader", e); } } Task<BasicMachineDetails> task = new PlainSshExecTaskFactory<String>(location, script) .summary("Getting machine details for: " + location).requiringZeroAndReturningStdout() .returning(taskToMachineDetailsFunction(location)).newTask().asTask(); return task; }
From source file:cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.java
public void setupLoadOnly(String deobfFileName, boolean loadAll) { try {/*from ww w . j a v a 2 s .c o m*/ File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); } else if ("MD".equals(typ) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:org.kohsuke.stapler.export.ExportedBeanAPT6.java
public void load(final InputStream is) throws IOException { beans.addAll(CharStreams.readLines(new InputStreamReader(is, Charsets.UTF_8))); }
From source file:com.google.dart.tools.debug.core.util.DebuggerUtils.java
public static String extractFileLine(InputStream contents, String charset, int lineNumber) { if (contents == null) { return null; }/*from www .j a v a 2s .co m*/ try { Reader r = charset != null ? new InputStreamReader(contents, charset) : new InputStreamReader(contents); List<String> lines = CharStreams.readLines(r); Closeables.close(r, true); if (lineNumber >= 0 && lineNumber < lines.size()) { String lineStr = lines.get(lineNumber).trim(); return lineStr.length() == 0 ? null : lineStr; } } catch (IOException ioe) { } return null; }