md5Out.close(); assert md5Out.getChecksumString().equals(calculateMd5(tempFile));
/** * Tests {@link AbstractFile#getAppendOutputStream()} when the operation is supported. * * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ protected void testGetAppendOutputStreamSupported() throws IOException, NoSuchAlgorithmException { // Assert that: // - getAppendOutputStream does not throw an IOException // - returns a non-null value // - the file exists after OutputStream out = tempFile.getAppendOutputStream(); assert out != null; assert tempFile.exists(); assert 0 == tempFile.getSize(); out.close(); // Assert that getAppendOutputStream() does not overwrite the existing file contents. // Appending to the file may not be supported, catch IOException thrown by getAppendOutputStream() and only those createFile(tempFile, 1); out = tempFile.getAppendOutputStream(); out.write('a'); out.close(); assert 2 == tempFile.getSize(); // Test the integrity of the OutputStream after writing a somewhat large amount of random data ChecksumOutputStream md5Out = getMd5OutputStream(tempFile.getOutputStream()); writeRandomData(md5Out, 100000, 1000); md5Out.close(); assert md5Out.getChecksumString().equals(calculateMd5(tempFile)); }
/** * Tests {@link AbstractFile#getOutputStream()} when the operation is supported. * * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ protected void testGetOutputStreamSupported() throws IOException, NoSuchAlgorithmException { // Assert that: // - getOutputStream does not throw an IOException // - returns a non-null value // - the file exists after OutputStream out = tempFile.getOutputStream(); assert out != null; assert tempFile.exists(); assert 0 == tempFile.getSize(); out.close(); // Assert that getOutputStream() overwrites the existing file contents (resets the file size to 0) createFile(tempFile, 1); out = tempFile.getOutputStream(); out.close(); assert 0 == tempFile.getSize(); // Test the integrity of the OutputStream after writing a somewhat large amount of random data ChecksumOutputStream md5Out = getMd5OutputStream(tempFile.getOutputStream()); writeRandomData(md5Out, 100000, 1000); md5Out.close(); assert md5Out.getChecksumString().equals(calculateMd5(tempFile)); }
md5Out.close(); assert md5Out.getChecksumString().equals(calculateMd5(tempFile)); tempFile.delete();