private void check(final TFile file) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(getDataLength()); try { file.output(out); } finally { out.close(); } assertTrue(Arrays.equals(getData(), out.toByteArray())); } }
void roundTrip(final int i) throws IOException { final TFile archive = newTempArchive(); final TFile file = new TFile(archive, i + getSuffix() + "/" + i); roundTrip(file); archive.rm_r(); }
private void roundTrip(final TFile outer) throws IOException { final TFile inner = new TFile(outer.getParentFile(), "inner" + getSuffix() + "/" + outer.getName()); // This particular sequence has been selected because of its increased // likeliness to fail in case the cache sync logic is not correct. create(inner); check(inner); inner.mv(outer); check(outer); outer.mv(inner); check(inner); inner.rm(); }
private TFile newTempArchive() throws IOException { // TODO: Removing .getCanonicalFile() causes archive.rm_r() to // fail in testCopyContainingOrSameFiles() - explain why! final File temp = File.createTempFile(TEMP_FILE_PREFIX, getSuffix()) .getCanonicalFile(); TFile.rm(temp); return new TFile(temp); }
private void create(final TFile file) throws IOException { final OutputStream out = new TFileOutputStream(file); try { out.write(getData()); } finally { out.close(); } assertEquals(getDataLength(), file.length()); }