示例#1
0
  @Test
  public void testGetBytes() {
    try {
      FileInputStream in = new FileInputStream(new File(dataRoot, "file/a.txt"));
      byte[] data = StreamUtil.readBytes(in);
      StreamUtil.close(in);

      String s = new String(data);
      s = StringUtil.remove(s, '\r');
      assertEquals("test file\n", s);

      in = new FileInputStream(new File(dataRoot, "file/a.txt"));
      String str = new String(StreamUtil.readChars(in));
      StreamUtil.close(in);
      str = StringUtil.remove(str, '\r');
      assertEquals("test file\n", str);
    } catch (FileNotFoundException e) {
      fail("StreamUtil.testGetBytes " + e.toString());
    } catch (IOException e) {
      fail("StreamUtil.testGetBytes " + e.toString());
    }
  }
示例#2
0
  @Test
  public void testCompare() {
    try {
      File file = new File(dataRoot, "file/a.txt");
      FileInputStream in1 = new FileInputStream(file);

      String content = "test file\r\n";
      if (file.length() == 10) {
        content = StringUtil.remove(content, '\r');
      }
      AsciiInputStream in2 = new AsciiInputStream(content);
      assertTrue(StreamUtil.compare(in1, in2));
      StreamUtil.close(in2);
      StreamUtil.close(in1);
    } catch (FileNotFoundException e) {
      fail("StreamUtil.testCloneCompare " + e.toString());
    } catch (IOException e) {
      fail("StreamUtil.testCloneCompare " + e.toString());
    }
  }