コード例 #1
0
ファイル: IOUtilsTest.java プロジェクト: marcpawl/vassal
  @Test
  public void testCopyBuffer() throws IOException {
    final byte[] buf = new byte[1024];

    final byte[] expected = new byte[10000];
    final long seed = System.currentTimeMillis();
    final Random rng = new Random(seed);
    rng.nextBytes(expected);

    final ByteArrayInputStream in = new ByteArrayInputStream(expected);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    final int count = IOUtils.copy(in, out, buf);

    assertEquals("seed == " + seed, expected.length, count);
    assertArrayEquals("seed == " + seed, expected, out.toByteArray());
  }
コード例 #2
0
ファイル: IOUtilsTest.java プロジェクト: marcpawl/vassal
  @Test
  public void testCopyLargeFileChannels() throws IOException {
    final File ifile = new File("test/VASSAL/tools/io/IOUtilsTest.java");
    final File ofile = new File("test/VASSAL/tools/io/test.out");

    try {
      final FileInputStream in = new FileInputStream(ifile);
      final FileOutputStream out = new FileOutputStream(ofile);

      final long count = IOUtils.copy(in, out);

      assertEquals(ifile.length(), count);
      assertTrue(FileUtils.contentEquals(ifile, ofile));
    } finally {
      ofile.delete();
    }
  }