예제 #1
0
 public void test_of_ioException() {
   assertThrows(
       () ->
           PropertiesFile.of(
               Files.asCharSource(new File("src/test/resources"), StandardCharsets.UTF_8)),
       UncheckedIOException.class);
 }
 public static PJsonObject parseJSONObjectFromFile(Class<?> testClass, String fileName)
     throws IOException {
   final File file = getFile(testClass, fileName);
   final Charset charset = Charset.forName(Constants.DEFAULT_ENCODING);
   String jsonString = Files.asCharSource(file, charset).read();
   Matcher matcher = IMPORT_PATTERN.matcher(jsonString);
   while (matcher.find()) {
     final String importFileName = matcher.group(1);
     File importFile = new File(file.getParentFile(), importFileName);
     final String tagToReplace = matcher.group();
     final String importJson = Files.asCharSource(importFile, charset).read();
     jsonString = jsonString.replace(tagToReplace, importJson);
     matcher = IMPORT_PATTERN.matcher(jsonString);
   }
   return parseJSONObjectFromString(jsonString);
 }
예제 #3
0
 private static DeadCodeMap loadDeadCodeMap() {
   File file = Options.getProGuardUsageFile();
   if (file != null) {
     try {
       return ProGuardUsageParser.parse(Files.asCharSource(file, Charset.defaultCharset()));
     } catch (IOException e) {
       throw new AssertionError(e);
     }
   }
   return null;
 }
예제 #4
0
 public static void consumeLines(File file, Charset charset, Consumer<String> consumer) {
   try {
     CharSource charSource = com.google.common.io.Files.asCharSource(file, charset);
     try (BufferedReader bufferedReader = charSource.openBufferedStream()) {
       for (String line; (line = bufferedReader.readLine()) != null; ) {
         try {
           consumer.accept(line);
         } catch (Exception e) {
           throw new IllegalStateException(e);
         }
       }
     }
   } catch (IOException e) {
     throw new IllegalArgumentException(e);
   }
 }
  @Override
  public @Nullable FullHttpResponse handleRequest(ChannelHandlerContext ctx, HttpRequest request)
      throws Exception {

    File glowrootLogFile = new File(logDir, "glowroot.log");
    CharSource glowrootLogCharSource = Files.asCharSource(glowrootLogFile, Charsets.UTF_8);

    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
    boolean keepAlive = HttpUtil.isKeepAlive(request);
    if (keepAlive && !request.protocolVersion().isKeepAliveDefault()) {
      response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }
    HttpServices.preventCaching(response);
    ctx.write(response);
    ChannelFuture future = ctx.write(ChunkedInputs.from(ChunkSource.from(glowrootLogCharSource)));
    HttpServices.addErrorListener(future);
    if (!keepAlive) {
      HttpServices.addCloseListener(future);
    }
    // return null to indicate streaming
    return null;
  }
 /** Append the contents of the file to the supplied appendable. */
 public void appendTo(Appendable out, DependencyInfo info, File content, Charset contentCharset)
     throws IOException {
   appendTo(out, info, Files.asCharSource(content, contentCharset));
 }