use of com.google.common.io.CharSource in project beam by apache.
the class ZipFilesTest method testAsCharSource.
@Test
public void testAsCharSource() throws Exception {
File zipDir = new File(tmpDir, "zip");
assertTrue(zipDir.mkdirs());
createFileWithContents(zipDir, "myTextFile.txt", "Simple Text");
ZipFiles.zipDirectory(tmpDir, zipFile);
try (ZipFile zip = new ZipFile(zipFile)) {
ZipEntry entry = zip.getEntry("zip/myTextFile.txt");
CharSource charSource = ZipFiles.asCharSource(zip, entry, StandardCharsets.UTF_8);
assertEquals("Simple Text", charSource.read());
}
}
use of com.google.common.io.CharSource in project GeoGig by boundlessgeo.
the class ConsoleResourceResource method getLimitedOutput.
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');
count += line.length();
if (count >= limit) {
output.append("\nNote: output limited to ").append(count).append(" characters. Run config web.console.limit <newlimit> to change the current ").append(limit).append(" soft limit.");
break;
}
}
return output;
}
use of com.google.common.io.CharSource in project GeoGig by boundlessgeo.
the class GlobalState method runAndParseCommand.
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;
}
Aggregations