Beispiel #1
0
 @Test
 public void testCopyFile_File_File() throws Exception {
   System.out.println("copyFile");
   File in = new File(testDir + "20100618/test1.txt");
   File out = new File(testDir + "20100618/test2.txt");
   IOUtils.copyFile(in, out);
   String a = IOUtils.readFile(out.getCanonicalPath());
   String b = IOUtils.readFile(in.getCanonicalPath());
   assertEquals(a, b);
 }
Beispiel #2
0
  /** Test of saveObject method, of class IOUtils. */
  @Test
  public void testSaveLoadObject() {
    System.out.println("saveObject");
    String[] saveObj = {"blah", "blah1", "blah2"};
    String addr = testDir + "20100618/obj1.oats";
    IOUtils.saveObject(saveObj, addr);

    String[] result = (String[]) IOUtils.loadObject(addr);
    assertEquals(saveObj, result);
  }
Beispiel #3
0
 @Test
 public void testCopyFile_String_String() throws Exception {
   System.out.println("copyFile");
   String in = testDir + "20100618/test1.txt";
   String out = testDir + "20100618/test2.txt";
   IOUtils.copyFile(in, out);
   String a = IOUtils.readFile(out);
   String b = IOUtils.readFile(in);
   assertEquals(a, b);
 }
Beispiel #4
0
  /** Test of writeString2File method, of class IOUtils. */
  @Test
  public void testWriteString2File() throws Exception {
    System.out.println("writeString2File");
    String expected = "blah blah blah\n";
    String addr = testDir + "20100618/test1.txt";
    IOUtils.writeString2File(expected, addr);

    String actual = IOUtils.readFile(addr);
    assertEquals(expected, actual);
  }
Beispiel #5
0
  /** Test of StringArrToFile method, of class IOUtils. */
  @Test
  public void testStringArrToFile() {
    System.out.println("StringArrToFile");
    String[] sortedLines = {"line1", "line2", "line3"};
    String addr2 = testDir + "20100618/stringArrToFile.txt";
    String newline = "\n";
    IOUtils.StringArrToFile(sortedLines, addr2, newline);

    String result = IOUtils.readFile(addr2);
    System.out.println(result);
    String expected = "line1\nline2\nline3\n";

    assertEquals(expected, result);
  }
Beispiel #6
0
 @Test
 public void testCloseQuietlySocketOpen() {
   final Socket s = new Socket();
   assertFalse(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Beispiel #7
0
 @Test
 public void testCloseQuietlyServerSocketOpen() throws IOException {
   final ServerSocket s = new ServerSocket(0);
   assertFalse(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Beispiel #8
0
  @Test
  public void testCloseQuietlyImageInputStreamClosed() throws IOException {
    final ImageInputStream in = new MemoryCacheImageInputStream(new ClosedInputStream());
    in.close();

    IOUtils.closeQuietly(in);
  }
Beispiel #9
0
 @Test
 public void testFileNameExtention() {
   System.out.println("fileNameExtention");
   File srcImg = new File(testDir + "20110116/frame0001.jpg");
   String expResult = "jpg";
   String result = IOUtils.fileNameExtention(srcImg);
   assertEquals(expResult, result);
 }
Beispiel #10
0
 @Test
 public void testReadFile() {
   System.out.println("readFile");
   String in = testDir + "20100618/test1.txt";
   String expResult = "blah blah blah\n";
   String result = IOUtils.readFile(in);
   assertEquals(expResult, result);
 }
Beispiel #11
0
 @Test
 public void testFileNameExtention_File() {
   System.out.println("testFileNameExtention_File");
   File file = new File("/temp1.jpgs");
   String expected = "jpgs";
   String result = IOUtils.fileNameExtention(file);
   assertEquals(expected, result);
 }
Beispiel #12
0
 /** Test of fileToString method, of class IOUtils. */
 @Test
 public void testFileToString() throws Exception {
   System.out.println("fileToString");
   String filename = testDir + "20100618/test3.txt";
   String expResult = "abfk1\n";
   String result = IOUtils.fileToString(filename);
   assertEquals(expResult, result);
 }
Beispiel #13
0
 @Test
 public void testCloseQuietlySocketClosed() throws IOException {
   final Socket s = new Socket();
   s.close();
   assertTrue(s.isClosed());
   IOUtils.closeQuietly(s);
   assertTrue(s.isClosed());
 }
Beispiel #14
0
 /** Test of intArr2Str method, of class IOUtils. */
 @Test
 public void testIntArr2Str() {
   System.out.println("intArr2Str");
   int[] idxRing = {1, 2, 3};
   String expResult = "1 2 3";
   String result = IOUtils.intArr2Str(idxRing);
   assertEquals(expResult, result);
 }
Beispiel #15
0
  @Test
  public void testReadClosed() throws IOException {
    final InputStream in = new ClosedInputStream();
    final byte[] buf = new byte[1];
    final int count = IOUtils.read(in, buf);

    assertEquals(-1, count);
    assertArrayEquals(new byte[1], buf);
  }
Beispiel #16
0
 @Test
 public void testImagesInDir_File_boolean() {
   System.out.println("test Images In Dir File Boolean");
   System.out.println("imagesInDir");
   File dir = new File(this.testDir + "20101015/");
   boolean traverse_subdirs = false;
   File[] expResult = {new File(testDir + "20101015/test1.jpg")};
   File[] result = IOUtils.imagesInDir(dir, traverse_subdirs);
   assertEquals(expResult, result);
 }
Beispiel #17
0
 @Test
 public void testTouch() {
   System.out.println("touch");
   File file = new File(testDir + "20101015/touch");
   //        System.out.println(file.toString());
   file.delete();
   IOUtils.touch(file);
   assertTrue(file.exists());
   file.delete();
 }
Beispiel #18
0
  @Test
  public void testReadFull() throws IOException {
    final byte[] expected = new byte[100];
    Arrays.fill(expected, (byte) 1);

    final InputStream in = new ByteArrayInputStream(expected);
    final byte[] actual = new byte[100];
    final int count = IOUtils.read(in, actual);

    assertEquals(expected.length, count);
    assertArrayEquals(expected, actual);
  }
Beispiel #19
0
  @Test
  public void testCloseQuietlyZipFileOpen() throws IOException {
    final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip");
    IOUtils.closeQuietly(zf);

    try {
      zf.size();
      fail();
    } catch (IllegalStateException e) {
      // This is the expected behavior of size().
    }
  }
Beispiel #20
0
  @Test
  public void testReadShort() throws IOException {
    final byte[] expected = new byte[50];
    Arrays.fill(expected, (byte) 1);

    final InputStream in = new ByteArrayInputStream(expected);
    final byte[] actual = new byte[100];
    final int count = IOUtils.read(in, actual);

    assertEquals(50, count);
    assertArrayEquals(expected, Arrays.copyOfRange(actual, 0, count));
    assertArrayEquals(new byte[50], Arrays.copyOfRange(actual, count, 100));
  }
Beispiel #21
0
  @Test
  public void testCloseQuietlyImageInputStreamOpen() {
    final ImageInputStream in = new MemoryCacheImageInputStream(new NullInputStream(1000));

    IOUtils.closeQuietly(in);

    try {
      in.close();
      fail();
    } catch (IOException e) {
      // This, oddly, the expected behavior of close().
    }
  }
Beispiel #22
0
  @Test
  public void testCloseQuietlyCloseableOk() throws IOException {
    final Closeable c = context.mock(Closeable.class);

    context.checking(
        new Expectations() {
          {
            oneOf(c).close();
          }
        });

    IOUtils.closeQuietly(c);
  }
Beispiel #23
0
  @Test
  public void testImagesInDir_String_boolean() {
    System.out.println("imagesInDir");

    String dirAddr = this.testDir + "20101015/";
    boolean traverse_subdirs = false;
    File e1 = new File(dirAddr + "test1.jpg");
    File[] expected = {e1};
    File[] result = IOUtils.imagesInDir(dirAddr, traverse_subdirs);
    assertEquals(expected.length, result.length);
    Arrays.sort(expected);
    Arrays.sort(result);
    assertEquals(expected[0].getAbsoluteFile(), result[0].getAbsoluteFile());
  }
Beispiel #24
0
  @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();
    }
  }
Beispiel #25
0
  @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());
  }
Beispiel #26
0
 @Test
 public void testCloseQuietlySocketNull() {
   IOUtils.closeQuietly((Socket) null);
 }
Beispiel #27
0
 @Test
 public void testCloseQuietlyZipFileClosed() throws IOException {
   final ZipFile zf = new ZipFile("test/VASSAL/tools/io/test.zip");
   zf.close();
   IOUtils.closeQuietly(zf);
 }
Beispiel #28
0
 @Test
 public void testCloseQuietlyZipFileNull() {
   IOUtils.closeQuietly((ZipFile) null);
 }
Beispiel #29
0
 @Test
 public void testCloseQuietlyImageInputStreamNull() {
   IOUtils.closeQuietly((ImageInputStream) null);
 }
Beispiel #30
0
 @Test
 public void testCloseQuietlyCloseableNull() {
   IOUtils.closeQuietly((Closeable) null);
 }