/** * Reads all of the lines from a {@link Readable} object. The lines do not include * line-termination characters, but do include other leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you should use the {@link * Files#readLines} and {@link Resources#readLines} methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
public static Optional<String> getMasterPassword(FileSystem fs, Path masterPasswordFile) { try (Closer closer = Closer.create()) { if (!fs.exists(masterPasswordFile) || fs.getFileStatus(masterPasswordFile).isDirectory()) { LOG.warn(masterPasswordFile + " does not exist or is not a file. Cannot decrypt any encrypted password."); return Optional.absent(); } InputStream in = closer.register(fs.open(masterPasswordFile)); return Optional.of(new LineReader(new InputStreamReader(in, Charsets.UTF_8)).readLine()); } catch (IOException e) { throw new RuntimeException("Failed to obtain master password from " + masterPasswordFile, e); } }
/** * Reads all of the lines from a {@link Readable} object. The lines do not include * line-termination characters, but do include other leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you should use the {@link * Files#readLines} and {@link Resources#readLines} methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads all of the lines from a {@link Readable} object. The lines do not include * line-termination characters, but do include other leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you should use the {@link * Files#readLines} and {@link Resources#readLines} methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Streams lines from a {@link Readable} object, stopping when the processor returns {@code false} * or all lines have been read and returning the result produced by the processor. Does not close * {@code readable}. Note that this method may not fully consume the contents of {@code readable} * if the processor stops processing early. * * @throws IOException if an I/O error occurs * @since 14.0 */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(Readable readable, LineProcessor<T> processor) throws IOException { checkNotNull(readable); checkNotNull(processor); LineReader lineReader = new LineReader(readable); String line; while ((line = lineReader.readLine()) != null) { if (!processor.processLine(line)) { break; } } return processor.getResult(); }
@Override public MessageCheckpoint fromBytes(final byte[] data) { try { final LineReader reader = new LineReader(new StringReader(new String(data, Charsets.UTF_8))); final int version = Integer.parseInt(reader.readLine()); switch (version) { case VERSION_V1: return new MessageCheckpoint(true, -1, new HashMap<>()); case VERSION_V2: return parseV2(reader); default: throw new RuntimeException("unknown snapshot content version " + version); } } catch (IOException e) { throw new RuntimeException(e); } }
@Override public ActionCheckpoint fromBytes(final byte[] data) { try { final LineReader reader = new LineReader(new StringReader(new String(data, Charsets.UTF_8))); final int version = Integer.parseInt(reader.readLine()); switch (version) { case VERSION_V1: return parseBySplitter(reader, COMMA_SPLITTER); case VERSION_V2: return parseBySplitter(reader, SLASH_SPLITTER); case VERSION_V3: return parseV3(reader); default: throw new RuntimeException("unknown snapshot content version " + version); } } catch (IOException e) { throw new RuntimeException(e); } }
private static List<String> readUsingReader(String input, int chunk, boolean asReader) throws IOException { Readable readable = asReader ? getChunkedReader(input, chunk) : getChunkedReadable(input, chunk); LineReader r = new LineReader(readable); List<String> lines = Lists.newArrayList(); String line; while ((line = r.readLine()) != null) { lines.add(line); } return lines; }
String masterPassword = new LineReader(new InputStreamReader(in, Charsets.UTF_8)).readLine(); TextEncryptor encryptor = useStrongEncryptor ? new StrongTextEncryptor() : new BasicTextEncryptor();
public GuidDatasetUrnStateStoreNameParser(FileSystem fs, Path jobStatestoreRootDir) throws IOException { this.fs = fs; this.sanitizedNameToDatasetURNMap = Maps.synchronizedBiMap(HashBiMap.<String, String>create()); this.versionIdentifier = new Path(jobStatestoreRootDir, StateStoreNameVersion.V1.getDatasetUrnNameMapFile()); if (this.fs.exists(versionIdentifier)) { this.version = StateStoreNameVersion.V1; try (InputStream in = this.fs.open(versionIdentifier)) { LineReader lineReader = new LineReader(new InputStreamReader(in, Charsets.UTF_8)); String shortenName = lineReader.readLine(); while (shortenName != null) { String datasetUrn = lineReader.readLine(); this.sanitizedNameToDatasetURNMap.put(shortenName, datasetUrn); shortenName = lineReader.readLine(); } } } else { this.version = StateStoreNameVersion.V0; } }
/** * Streams lines from a {@link Readable} object, stopping when the processor returns {@code false} * or all lines have been read and returning the result produced by the processor. Does not close * {@code readable}. Note that this method may not fully consume the contents of {@code readable} * if the processor stops processing early. * * @throws IOException if an I/O error occurs * @since 14.0 */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(Readable readable, LineProcessor<T> processor) throws IOException { checkNotNull(readable); checkNotNull(processor); LineReader lineReader = new LineReader(readable); String line; while ((line = lineReader.readLine()) != null) { if (!processor.processLine(line)) { break; } } return processor.getResult(); }
/** * Streams lines from a {@link Readable} object, stopping when the processor returns {@code false} * or all lines have been read and returning the result produced by the processor. Does not close * {@code readable}. Note that this method may not fully consume the contents of {@code readable} * if the processor stops processing early. * * @throws IOException if an I/O error occurs * @since 14.0 */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(Readable readable, LineProcessor<T> processor) throws IOException { checkNotNull(readable); checkNotNull(processor); LineReader lineReader = new LineReader(readable); String line; while ((line = lineReader.readLine()) != null) { if (!processor.processLine(line)) { break; } } return processor.getResult(); }
//Used to determine file size and then show in progress bar, app is threaded. byte[] fileBytes = IOUtilities.streamToBytes( is ); int totalFileSize = fileBytes.length; int totalRead = 0; ByteArrayInputStream bais = new ByteArrayInputStream( fileBytes ); LineReader lr = new LineReader( bais);
public static Optional<String> getMasterPassword(FileSystem fs, Path masterPasswordFile) { try (Closer closer = Closer.create()) { if (!fs.exists(masterPasswordFile) || fs.getFileStatus(masterPasswordFile).isDirectory()) { LOG.warn(masterPasswordFile + " does not exist or is not a file. Cannot decrypt any encrypted password."); return Optional.absent(); } InputStream in = closer.register(fs.open(masterPasswordFile)); return Optional.of(new LineReader(new InputStreamReader(in, Charsets.UTF_8)).readLine()); } catch (IOException e) { throw new RuntimeException("Failed to obtain master password from " + masterPasswordFile, e); } }
public static Optional<String> getMasterPassword(FileSystem fs, Path masterPasswordFile) { try (Closer closer = Closer.create()) { if (!fs.exists(masterPasswordFile) || fs.getFileStatus(masterPasswordFile).isDirectory()) { LOG.warn(masterPasswordFile + " does not exist or is not a file. Cannot decrypt any encrypted password."); return Optional.absent(); } InputStream in = closer.register(fs.open(masterPasswordFile)); return Optional.of(new LineReader(new InputStreamReader(in, Charsets.UTF_8)).readLine()); } catch (IOException e) { throw new RuntimeException("Failed to obtain master password from " + masterPasswordFile, e); } } }
/** * 显示文本LOGO */ public static final void textLogo(){ try(InputStreamReader reader = new InputStreamReader(Logo.class.getResourceAsStream("/logotext.txt"))) { LineReader lineReader = new LineReader(reader); String line ; while(null != (line = lineReader.readLine())){ System.out.println(line); } } catch (IOException e) { throw new RuntimeException(e); } }
private void readPreferences(Reader reader) throws IOException { LineReader allLines = new LineReader(reader); String line = allLines.readLine(); while (line != null) { Matcher matcher = PREFERENCE_PATTERN.matcher(line); if (matcher.matches()) { allPrefs.put(matcher.group(1), preferenceAsValue(matcher.group(2))); } line = allLines.readLine(); } }
private void readPreferences(FileReader reader) throws IOException { LineReader allLines = new LineReader(reader); String line = allLines.readLine(); while (line != null) { Matcher matcher = PREFERENCE_PATTERN.matcher(line); if (matcher.matches()) { allPreferences.put(matcher.group(1), preferenceAsValue(matcher.group(2))); } line = allLines.readLine(); } }
private static List<String> readUsingReader(String input, int chunk, boolean asReader) throws IOException { Readable readable = asReader ? getChunkedReader(input, chunk) : getChunkedReadable(input, chunk); LineReader r = new LineReader(readable); List<String> lines = Lists.newArrayList(); String line; while ((line = r.readLine()) != null) { lines.add(line); } return lines; }
@Test public void simple() throws IOException { layout.start(); final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); final Logger logger = lc.getLogger(LOGGER_NAME); final String logMsg = layout.doLayout(simpleLoggingEvent(logger, null)); final ObjectMapper om = new ObjectMapper(); final JsonNode jsonNode = om.readTree(logMsg); basicValidation(jsonNode); final LineReader msg = new LineReader(new StringReader(jsonNode.get("full_message").textValue())); assertEquals("message 1", msg.readLine()); }