/** * Equivalent to * {@link TConfig#setArchiveDetector TConfig.get().setArchiveDetector(detector)}. */ public static void setDefaultArchiveDetector(TArchiveDetector detector) { TConfig.get().setArchiveDetector(detector); }
private static TConfig push(Map<String, ?> env) { final TArchiveDetector detector = (TArchiveDetector) env.get( Parameter.ARCHIVE_DETECTOR); final TConfig config = TConfig.push(); if (null != detector) config.setArchiveDetector(detector); return config; }
/** * @deprecated Calling this method is equivalent to * {@link TConfig#setArchiveDetector TConfig.get().setArchiveDetector(detector)}. * @see <a href="http://java.net/jira/browse/TRUEZIP-238">#TRUEZIP-238</a> */ @Deprecated public static void setDefaultArchiveDetector(TArchiveDetector detector) { TConfig.get().setArchiveDetector(detector); }
static void install(TArchiveDetector detector) { // START SNIPPET: install TConfig.get().setArchiveDetector(detector); // END SNIPPET: install }
/** * Constructor */ public ModuleManagementTool() { TConfig config = TConfig.get(); config.setArchiveDetector(new TArchiveDetector("war|amp", new JarDriver(IOPoolLocator.SINGLETON))); // Load the default file mapping properties this.defaultFileMappingProperties = new Properties(); InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE_MAPPING_PROPERTIES); try { this.defaultFileMappingProperties.load(is); } catch (IOException exception) { throw new ModuleManagementToolException("Unable to load default extension file mapping properties.", exception); } }
/** * Constructor */ public ModuleManagementTool() { TConfig config = TConfig.get(); config.setArchiveDetector(new TArchiveDetector("war|amp", new JarDriver(IOPoolLocator.SINGLETON))); // Load the default file mapping properties this.defaultFileMappingProperties = new Properties(); InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE_MAPPING_PROPERTIES); try { this.defaultFileMappingProperties.load(is); } catch (IOException exception) { throw new ModuleManagementToolException("Unable to load default extension file mapping properties.", exception); } }
try { TConfig.get().setArchiveDetector(newArchiveDetector()); TConfig.get().setArchiveDetector(oldDetector);
final TConfig config = TConfig.push(); try { config.setArchiveDetector(TArchiveDetector.NULL); final TPath fileName = getFileName(); assert null != fileName : "an archive file must not have an empty path name!";
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(); }
@PostConstruct public void init() { TConfig.get().setArchiveDetector( new TArchiveDetector( TArchiveDetector.NULL, new Object[][] { { "tar|ova", new TarDriver( IOPoolLocator.SINGLETON ) }, { "tgz|tar.gz", new TarGZipDriver( IOPoolLocator.SINGLETON ) }, { "tbz2|tar.bz2", new TarBZip2Driver( IOPoolLocator.SINGLETON ) }, { "zip|kar", new ZipDriver( IOPoolLocator.SINGLETON ) }, { "jar|war|ear|sar|swc|nar|esb|par", new JarDriver( IOPoolLocator.SINGLETON ) }, } ) ); } }
public WarHelperImplTest() { super(new LogOutput() { @Override public void info(Object message) { System.out.println(message); } }); TConfig config = TConfig.get(); config.setArchiveDetector(new TArchiveDetector("war|amp", new ZipDriver(IOPoolLocator.SINGLETON))); }
@Override public void setUp() throws IOException { super.setUp(); detector = new TArchiveDetector(getSuffixList(), getArchiveDriver()); environment = Collections.singletonMap(ARCHIVE_DETECTOR, detector); final TConfig config = TConfig.push(); // Using a private file system manager would normally violate the third // party access constraints, but in this context it's safe because no // two test methods should ever access the same archive file(s) except // when performing a sync of all mounted file systems. // Mind that a sync should always succeed (unless there's an issue in // the parent file system) und must not confuse other threads about the // state of the synced archive file(s). // So the default value 'false' helps to identify potential isolation // issues in case this invariant is not met. // See http://truezip.java.net/truezip-file/usage.html#Third_Party_Access if (ISOLATE_FS_MANAGER) config.setFsManager(new FsDefaultManager()); config.setLenient(true); config.setArchiveDetector(detector); }
@Test public void testConfiguration() { // Create reference to the current directory. TPath directory = new TPath(""); // This is how you would detect a prospective archive file. TPath archive = directory.resolve("archive.mok"); TPath file; TConfig config = TConfig.push(); try { config.setArchiveDetector(TArchiveDetector.NULL); // Ignore prospective archive file here. file = directory.resolve("archive.mok"); } finally { config.close(); } // Once created, the prospective archive file detection does not change // because a TPath is immutable. assert archive.getArchiveDetector() == getArchiveDetector(); assert archive.isArchive(); assert file.getArchiveDetector() == TArchiveDetector.NULL; assert !file.isArchive(); } }
@Test public void standardUseCase() { TFile f1 = new TFile("file.mok"); assertFalse(f1.isArchive()); // Push a new current configuration on the thread local stack. TConfig c = TConfig.push(); try { // Change the inheritable thread local configuration. c.setArchiveDetector( new TArchiveDetector("mok", new MockArchiveDriver())); // Use the inheritable thread local configuration. TFile f2 = new TFile("file.mok"); assertTrue(f2.isArchive()); // Do some I/O here. } finally { // Pop the configuration off the inheritable thread local stack. c.close(); } }
final TConfig c2 = TConfig.push(); try { c2.setArchiveDetector(ad2); assertThat(TConfig.get(), sameInstance(c2)); assertThat(c2.getArchiveDetector(), sameInstance(ad2)); final TConfig c3 = TConfig.push(); try { c3.setArchiveDetector(ad3); assertThat(TConfig.get(), sameInstance(c3)); assertThat(c3.getArchiveDetector(), sameInstance(ad3));