private static TArchiveDetector getDetector(File file) { return file instanceof TFile ? ((TFile) file).getArchiveDetector() : TConfig.get().getArchiveDetector(); } }
/** * Ensures that the returned file object is an instance of {@link File}, * not {@link TFile}. */ protected File unwrap(final File file) { return file instanceof TFile ? ((TFile) file).getFile() : file; }
/** * Gets the bean's <code>MethodDescriptor</code>s. * * @return An array of MethodDescriptors describing the methods * implemented by this bean. May return null if the information * should be obtained by automatic analysis. */ @Override public MethodDescriptor[] getMethodDescriptors() { return getMdescriptor(); }
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(); }
void performance2() throws IOException { // START SNIPPET: performance2 String[] names = {"a", "b", "c"}; int n = names.length; for (int i = 0; i < n; i++) { // n * ... TFile entry = new TFile("archive.zip", names[i]); // O(1) entry.createNewFile(); // O(1) } TVFS.umount(); // new file: O(1); modified: O(n) // Overall: O(n) // END SNIPPET: performance2 }
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(); }
@Override public void setUp() throws IOException { super.setUp(); temp = createTempFile(); TFile.rm(temp); archive = new TFile(temp); }
/** * Equivalent to * {@link TConfig#setArchiveDetector TConfig.get().setArchiveDetector(detector)}. */ public static void setDefaultArchiveDetector(TArchiveDetector detector) { TConfig.get().setArchiveDetector(detector); }
@Test public final void testInputOutput() throws IOException { assertInputOutput(archive); final TFile archiveTest = new TFile(archive, "test"); assertInputOutput(archiveTest); final TFile archiveInner = new TFile(archive, "inner" + getSuffix()); final TFile archiveInnerTest = new TFile(archiveInner, "test"); assertInputOutput(archiveInnerTest); archiveInner.rm(); archive.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); }
/** * Equivalent to * {@link TConfig#getArchiveDetector TConfig.get().getArchiveDetector()}. */ public static TArchiveDetector getDefaultArchiveDetector() { return TConfig.get().getArchiveDetector(); }
private void createTestArchive(final int nEntries) throws IOException { for (int i = 0; i < nEntries; i++) createTestFile(new TFile(archive, i + "")); }
private void assertInputOutput(final TFile file) throws IOException { assertInput(file); assertOutput(file); file.rm(); }
@Override public OutputStream create(String entry) throws IOException { return new TFileOutputStream(entry); } });
private void assertCopyContainingOrSameFiles0(final TFile a, final TFile b) throws IOException { assertCopyContainingOrSameFiles1(a, b); assertCopyContainingOrSameFiles1(a.getCanOrAbsFile(), b); assertCopyContainingOrSameFiles1(a, b.getCanOrAbsFile()); assertCopyContainingOrSameFiles1(a.getCanOrAbsFile(), b.getCanOrAbsFile()); }
/** * Equivalent to {@link #rm_r(File) rm_r(this)}. * * @return {@code this} * @throws IOException if any I/O error occurs. * @see <a href="#bulkIOMethods">Bulk I/O Methods</a> * @see <a href="#traversal">Traversing Directory Trees</a> */ public TFile rm_r() throws IOException { TBIO.rm_r(this, detector); return this; }
void performance1() throws IOException { // START SNIPPET: performance1 String[] names = {"a", "b", "c"}; int n = names.length; for (int i = 0; i < n; i++) { // n * ... TFile entry = new TFile("archive.zip", names[i]); // O(1) entry.createNewFile(); // O(1) TVFS.umount(); // O(i + 1) !! } // Overall: O(n*n) !!! // END SNIPPET: performance1 }