/** Copy constructor for inheritable thread local configurations. */ private TConfig(final TConfig template) { this.manager = template.getFsManager(); this.detector = template.getArchiveDetector(); this.inputPreferences = template.getInputPreferences(); this.outputPreferences = template.getOutputPreferences(); }
/** * Deletes the given file or directory. * If the file is a directory, it must be empty. * * @param node the file or directory. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @throws IOException if any I/O error occurs. * @see <a href="#bulkIOMethods">Bulk I/O Methods</a> */ public static void rm(File node) throws IOException { if (node instanceof TFile) { TFile file = (TFile) node; if (null != file.innerArchive) { file.innerArchive.getController().unlink( file.getInnerFsEntryName(), TConfig.get().getOutputPreferences()); return; } node = file.file; } if (!node.delete()) throw new IOException(node + " (cannot delete)"); }
BitField<FsOutputOption> getOutputPreferences() { final BitField<FsOutputOption> prefs = TConfig .get() .getOutputPreferences(); return null != getMountPoint().getParent() ? prefs : prefs.clear(CREATE_PARENTS); }
@CreatesObligation private static OutputStream newOutputStream(final File dst, final boolean append) throws FileNotFoundException { final OutputSocket<?> output = TBIO.getOutputSocket(dst, TConfig.get().getOutputPreferences().set(APPEND, append), null); try { return output.newOutputStream(); } catch (FileNotFoundException ex) { throw ex; } catch (IOException ex) { throw (FileNotFoundException) new FileNotFoundException( dst.toString()).initCause(ex); } } }
getInnerFsEntryName(), DIRECTORY, TConfig.get().getOutputPreferences(), null); return true;
BitField.of(Access.WRITE), time, TConfig.get().getOutputPreferences()); return true; } catch (IOException ex) {
innerEntryName, DIRECTORY, TConfig.get().getOutputPreferences(), null); } catch (IOException ex) {
/** Unchecked parameters version. */ private static void cp0(final boolean preserve, final File src, final File dst) throws IOException { final TConfig config = TConfig.get(); final InputSocket<?> input = getInputSocket(src, config.getInputPreferences()); final OutputSocket<?> output = getOutputSocket(dst, config.getOutputPreferences(), preserve ? input.getLocalTarget() : null); IOSocket.copy(input, output); }
/** * Creates a new, empty file similar to its superclass implementation. * Note that this method doesn't create archive files because archive * files are virtual directories, not files! * * @see #mkdir */ @Override public boolean createNewFile() throws IOException { if (null != innerArchive) { final FsController<?> controller = innerArchive.getController(); final FsEntryName entryName = getInnerFsEntryName(); // FIXME: This is not properly isolated. if (null != controller.getEntry(entryName)) return false; controller.mknod( entryName, FILE, TConfig.get().getOutputPreferences().set(EXCLUSIVE), null); return true; } return file.createNewFile(); }
try { final TConfig config = TConfig.get(); // Request encryption in archive files. config.setOutputPreferences(config.getOutputPreferences() .or(BitField.of(FsOutputOption.ENCRYPT))); // Configure archive detector with custom key management for ZIP files. config.setArchiveDetector(newArchiveDetector1("zip", "password")); // Setup file paths. TFile src = new TFile("file1"); TFile dst = new TFile("file2"); if (dst.isArchive() || dst.isDirectory()) dst = new TFile(dst, src.getName()); // Recursive copy. src.cp_rp(dst); } finally { // Commit changes. TVFS.umount(); }
config.setOutputPreferences(config.getOutputPreferences() .set(STORE, store) .set(COMPRESS, compress)
@Override public void setUp() throws IOException { super.setUp(); final TConfig config = TConfig.get(); config.setOutputPreferences(config.getOutputPreferences().set(ENCRYPT)); }
@Override public void setUp() throws IOException { super.setUp(); final TConfig config = TConfig.get(); config.setOutputPreferences(config.getOutputPreferences().set(ENCRYPT)); }
@Test public void defaults() { final TConfig c = TConfig.get(); assertThat(TConfig.get(), sameInstance(c)); final TArchiveDetector detector = c.getArchiveDetector(); assertThat(detector, sameInstance(TArchiveDetector.ALL)); assertThat(c.getArchiveDetector(), sameInstance(detector)); final boolean lenient = c.isLenient(); assertThat(lenient, is(true)); assertThat(c.isLenient(), is(lenient)); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); }
config.getOutputPreferences().clear(GROW));
config.setOutputPreferences(config.getOutputPreferences().set(GROW)); config.setOutputPreferences(config.getOutputPreferences().set(GROW));
assertTrue(c.isLenient()); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getOutputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertThat(c.getOutputPreferences(), is(BitField.of(CACHE))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertThat(c.getOutputPreferences(), is(BitField.of(STORE))); assertThat(c.getOutputPreferences(), is(BitField.of(COMPRESS))); assertThat(c.getOutputPreferences(), is(BitField.of(GROW))); assertThat(c.getOutputPreferences(), is(BitField.of(CACHE, CREATE_PARENTS, COMPRESS))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS)));
config.setOutputPreferences(config.getOutputPreferences().set(GROW)); config.setOutputPreferences(config.getOutputPreferences().set(GROW));