// Call this once at application startup to make the ZipDriver a compile time // dependency. TFile.setDefaultArchiveDetector( new TArchiveDetector( "zip", new ZipDriver(IOPoolLocator.SINGLETON))); // Here's the work. TFile src = new TFile(this.getMellomStasjon()); TFile dst = new TFile(this.getZipFolder(), zipFile + ".zip"); TFile.cp_rp(src, dst, TArchiveDetector.NULL); TFile.umount(dst);
private @Nullable FsScheme getScheme() { if (this != innerArchive) return null; final FsController<?> controller = this.controller; if (null != controller) return controller.getModel().getMountPoint().getScheme(); return detector.getScheme(file.getPath()); }
final SuffixSet suffixes = extensions(provider); final Map<FsScheme, FsDriver> available = provider.get(); final Map<FsScheme, FsDriver> drivers = new HashMap<FsScheme, FsDriver>(
private void assertSuffixes(final String[] args) { for (int i = 0; i < args.length; ) { final String result = args[i++]; final String suffixes = args[i++]; TArchiveDetector detector = new TArchiveDetector(suffixes, driver); assertEquals(result, detector.toString()); detector = new TArchiveDetector(NIL, suffixes, driver); assertEquals(result, detector.toString()); detector = new TArchiveDetector(NIL, new Object[][] {{ suffixes, driver }}); assertEquals(result, detector.toString()); } }
@SuppressWarnings("AssignmentToForLoopParameter") private void assertScheme( final String[][] tests, final TArchiveDetector... detectors) { for (TArchiveDetector detector : detectors) { try { detector.getScheme(null); fail("Expected NullPointerException!"); } catch (NullPointerException expected) { } for (String[] test : tests) { final FsScheme scheme = test[0] == null ? null : FsScheme.create(test[0]); final String path = test[1]; assertScheme(detector, scheme, path); // Add level of indirection in order to test caching. detector = new TArchiveDetector(detector, new Object[0][0]); assertScheme(detector, scheme, path); } } }
private @Nullable FsDriver getDriver(FsScheme scheme) { return detector.get().get(scheme); }
@Test public void testNullMapping() { for (TArchiveDetector delegate : new TArchiveDetector[] { NIL, ALL, }) { TArchiveDetector detector = new TArchiveDetector( delegate, "zip", null); // remove zip suffix assertFalse(new SuffixSet(detector.toString()).contains("zip")); detector = new TArchiveDetector( delegate, ".ZIP", null); // remove zip suffix assertFalse(new SuffixSet(detector.toString()).contains("zip")); } }
@Before public void setUp() { driver = new MockArchiveDriver(); ALL = new TArchiveDetector("tar.gz|zip", driver); NIL = new TArchiveDetector(ALL, ""); // test decoration MOK = new TArchiveDetector(NIL, "nil", driver); // test decoration }
private void assertScheme( final TArchiveDetector detector, final @Nullable FsScheme scheme, final String path) { final String lpath = path.toLowerCase(Locale.ROOT); final String upath = path.toUpperCase(Locale.ROOT); assertThat(detector.getScheme(lpath), equalTo(scheme)); assertThat(detector.getScheme(upath), equalTo(scheme)); } }
final SuffixSet available = extensions(provider); SuffixSet accepted; if (null == suffixes) {
/** * 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); } }
final boolean isArchive = null != detector.getScheme(path); if (0 < enclEntryNameBuf.length()) { if (isArchive) {
/** * 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); } }
final File file = this.file; final String path = Paths.normalize(file.getPath(), separatorChar); final FsScheme scheme = detector.getScheme(path);
return new TArchiveDetector(TArchiveDetector.ALL, new Object[][] { { "ear|jar|war|zip", new CheckedZipDriver(POOL_PROVIDER) { // check CRC-32
mp = new FsPath(new FsMountPoint(ppu), men); final FsScheme s = detector.getScheme(men.toString()); if (null != s) mp = new FsPath(new FsMountPoint(s, mp), ROOT);
switch (args.length) { case 1: new TArchiveDetector((String) arg0); fail("Index " + i); break; if (arg1 != null) { if (arg0 instanceof String) new TArchiveDetector((String) arg0, (FsArchiveDriver<?>) arg1); else if (arg1 instanceof Object[][]) new TArchiveDetector((TArchiveDetector) arg0, (Object[][]) arg1); else new TArchiveDetector((TArchiveDetector) arg0, (Map<FsScheme, FsDriver>) arg1); fail("Index " + i); } else { assert arg1 == null; if (arg0 instanceof String) { new TArchiveDetector((String) arg0, null); fail("Index " + i); } else { try { new TArchiveDetector((TArchiveDetector) arg0, (Object[][]) null); fail("Index " + i); } catch (Throwable failure) { new TArchiveDetector((TArchiveDetector) arg0, (Map<FsScheme, FsDriver>) null); fail("Index " + i); } catch (Throwable failure) {
/** * May be overridden by subclasses to create the * {@link TArchiveDetector} which provides file system drivers which * should use the specified charset if supported. * <p> * Note that the archive detector which is returned by the implementation * in this class uses some archive drivers which may be pretty slow due to * some extra compatibility tests which they perform on every archive. */ protected TArchiveDetector newArchiveDetector() { return new TArchiveDetector(TArchiveDetector.ALL, new Object[][] { { "ear|jar|war", new CheckedJarDriver(POOL_PROVIDER) },// check CRC-32 { "zip", new CheckedZipDriver(POOL_PROVIDER) }, // check CRC-32 { "exe", new CheckedReadOnlySfxDriver(POOL_PROVIDER) }, // check CRC-32 }); }
/** * Returns a new archive detector which uses the given password for all * WinZip AES encrypted ZIP entries with the given list of suffixes. * <p> * When used for encryption, the AES key strength will be set to 128 bits. * <p> * A protective copy of the given password char array is made. * It's recommended to overwrite the parameter array with any non-password * data after calling this method. * * @param delegate the file system driver provider to decorate. * @param suffixes A list of file name suffixes which shall identify * prospective archive files. * This must not be {@code null} and must not be empty. * @param password the password char array to be copied for internal use. * The characters should be limited to US-ASCII, see * {@link WinZipAesParameters}. * @return A new archive detector which uses the given password for all * WinZip AES encrypted ZIP entries with the given list of suffixes. */ public static TArchiveDetector newArchiveDetector2( FsDriverProvider delegate, String suffixes, char[] password) { return new TArchiveDetector(delegate, suffixes, new CustomZipDriver2(password)); }
/** * Returns a new archive detector which uses the given password for all * WinZip AES encrypted ZIP entries with the given list of suffixes. * <p> * When used for encryption, the AES key strength will be set to 128 bits. * <p> * A protective copy of the given password char array is made. * It's recommended to overwrite the parameter array with any non-password * data after calling this method. * * @param delegate the file system driver provider to decorate. * @param suffixes A list of file name suffixes which shall identify * prospective archive files. * This must not be {@code null} and must not be empty. * @param password the password byte array to be copied for internal use. * The bytes should be limited to seven bits only, see * {@link WinZipAesParameters}. * @return A new archive detector which uses the given password for all * WinZip AES encrypted ZIP entries with the given list of suffixes. */ public static TArchiveDetector newArchiveDetector1( FsDriverProvider delegate, String suffixes, byte[] password) { return new TArchiveDetector(delegate, suffixes, new CustomZipDriver1(password)); }