Пример #1
0
  /**
   * Tests the read(buffer) method by reading a file one buffer at a time.
   *
   * @throws IOException
   */
  @Test
  public void testReadBuffer() throws IOException {
    byte[] buffer = new byte[1024];
    long buffersRead = 0;
    for (int bytesRead = pis.read(buffer); bytesRead != -1; bytesRead = pis.read(buffer)) {
      buffersRead++;
    }

    assertEquals(getExpectedBufferReads(file.length(), buffer.length), buffersRead);

    LOGGER.trace("Done");
  }
Пример #2
0
  /**
   * Tests the read(buffer, offset, length) method by read a file one buffer at the file using the
   * offset and length.
   *
   * @throws IOException
   */
  @Test
  public void testReadBufferOffLen() throws IOException {
    byte[] buffer = new byte[2048];
    int off = 512;
    int len = 1024;
    initByteArrayWith0(buffer);
    long buffersRead = 0;
    for (int bytesRead = pis.read(buffer, off, len);
        bytesRead != -1;
        bytesRead = pis.read(buffer, off, len)) {
      buffersRead++;
    }

    assertEquals(getExpectedBufferReads(file.length(), len), buffersRead);

    LOGGER.trace("Done");
  }
Пример #3
0
 @Before
 public void setUp() throws Exception {
   listenerCalledCount = 0;
   file = tempDir.newFile();
   writeRandomBytes(file, 5L * 1024L * 1024L);
   pis = new ProgressInputStream(new FileInputStream(file), file.length());
   pis.addPropertyChangeListener(createPropertyChangeListener());
 }
Пример #4
0
  /**
   * Tests the read() method by reading a file one byte at a time.
   *
   * @throws IOException
   */
  @Test
  public void testRead() throws IOException {
    int numBytesRead = 0;
    while (pis.read() != -1) numBytesRead++;

    assertEquals(file.length(), numBytesRead);

    LOGGER.trace("Done");
  }
Пример #5
0
 @After
 public void tearDown() throws Exception {
   assertTrue(listenerCalledCount >= 1 && listenerCalledCount <= 100);
   pis.close();
 }