@Test
  public void test_transformThreeRowsOfComplexXML() throws Exception {
    String xml = TRIPLE_ROW_MULTIPLE_ORG;

    makeTsv(xml);
    psr.setKeepElderInfo(false);
    psr.setRowElementName("Site");

    ByteStreams.copy(inn, tsv);
    tsv.close();

    String result = new String(out.toByteArray());
    System.err.println(result);

    StringReader reader = new StringReader(result);
    LineReader lines = new LineReader(reader);
    String line;

    line = lines.readLine();
    assertTrue(line.startsWith("\"code\"\t\"agency\"\t\"Id\"\t\"level\"\t\"Type\""));

    line = lines.readLine();
    assertTrue(line.startsWith("\"01\"\t\"\"\t\"2172257\"\t\"admin\"\t\"water\""));

    line = lines.readLine();
    assertTrue(line.startsWith("\"02\"\t\"USGS2\"\t\"\"\t\"\"\t\"clay\""));

    line = lines.readLine();
    assertTrue(line.startsWith("\"03\"\t\"\"\t\"2172258\"\t\"user\"\t\"stream\""));
  }
 /**
  * 将j.stack文件中有用的两行拿出来
  *
  * @param filename
  * @return
  */
 public List<String[]> getLine(String filename) throws Exception {
   if (filename == null) throw new FileNotFoundException();
   Closer closer = Closer.create();
   String[] rawData = {"", ""};
   List<String[]> rawDatas = new ArrayList<String[]>();
   URL url = Resources.getResource(filename);
   try {
     FileReader reader = closer.register(new FileReader(url.getPath()));
     LineReader lineReader = new LineReader(reader);
     String line = "";
     while ((line = lineReader.readLine()) != null) {
       if (line.indexOf("\"") > -1) { // 匹配第一行
         rawData = new String[2];
         rawData[0] = line;
       }
       if (line.indexOf("java.lang.Thread.State") > -1) { // 匹配第二行,取当前线程的状态
         rawData[1] = line.trim().split(" ")[1];
         rawDatas.add(rawData);
       }
     }
   } finally {
     closer.close();
   }
   return rawDatas;
 }
Beispiel #3
0
 default Mappings parse(Readable readable) throws IOException {
   LineReader lineReader = new LineReader(readable);
   LineProcessor<Mappings> lineProcessor = createLineProcessor();
   String line;
   while ((line = lineReader.readLine()) != null) {
     if (!lineProcessor.processLine(line)) {
       break;
     }
   }
   return lineProcessor.getResult();
 }
 public static <T> T readLines(Readable paramReadable, LineProcessor<T> paramLineProcessor)
   throws IOException
 {
   Preconditions.checkNotNull(paramReadable);
   Preconditions.checkNotNull(paramLineProcessor);
   LineReader localLineReader = new LineReader(paramReadable);
   String str;
   do
     str = localLineReader.readLine();
   while ((str != null) && (paramLineProcessor.processLine(str)));
   return paramLineProcessor.getResult();
 }
 public static List<String> readLines(Readable paramReadable)
   throws IOException
 {
   ArrayList localArrayList = new ArrayList();
   LineReader localLineReader = new LineReader(paramReadable);
   while (true)
   {
     String str = localLineReader.readLine();
     if (str == null)
       break;
     localArrayList.add(str);
   }
   return localArrayList;
 }
Beispiel #6
0
    protected TestSuite buildSuite() {
      TestSuite suite = new TestSuite("Shared Dart tests");

      if (!V8Launcher.isConfigured()) {
        return configurationProblem(
            suite, "Please set the system property com.google.dart.runner.d8");
      }

      File file = new File(listTests[0]);
      if (!file.canExecute()) {
        return configurationProblem(suite, file.getPath() + " is not executable");
      }
      ProcessBuilder builder = new ProcessBuilder(listTests);
      try {
        Process process = builder.start();
        InputStream inputStream = process.getInputStream();
        StringBuilder sb = new StringBuilder();
        try {
          InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
          LineReader lineReader = new LineReader(inputStreamReader);
          String line;
          while ((line = lineReader.readLine()) != null) {
            if (!line.startsWith("dartc/")) {
              suite.addTest(SharedTestCase.getInstance(line, false));
            } else if (line.startsWith("dartc/client/")) {
              suite.addTest(SharedTestCase.getInstance(line, true));
            }
          }
        } finally {
          inputStream.close();
          process.getOutputStream().close();
          InputStreamReader inputStreamReader = new InputStreamReader(process.getErrorStream());
          CharStreams.copy(inputStreamReader, sb);
          process.getErrorStream().close();
        }
        process.waitFor();
        if (process.exitValue() != 0) {
          sb.insert(0, file.getPath());
          sb.insert(0, " returned non-zero exit code.\n");
          return configurationProblem(suite, sb.toString());
        }
      } catch (IOException e) {
        throw new AssertionError(e);
      } catch (InterruptedException e) {
        throw new AssertionError(e);
      }
      return suite;
    }
  @Test
  public void test_transformTwoRowsOfSimplerXML() throws Exception {
    String xml = "<get><Site>2172257</Site><Site>2172258</Site></get>";
    makeTsv(xml);

    ByteStreams.copy(inn, tsv);
    tsv.close();

    String result = new String(out.toByteArray());
    System.err.println(result);

    StringReader reader = new StringReader(result);
    LineReader lines = new LineReader(reader);
    String line;

    line = lines.readLine();
    assertEquals("\"Site\"", line);

    line = lines.readLine();
    assertEquals("\"2172257\"", line);

    line = lines.readLine();
    assertEquals("\"2172258\"", line);
  }