Search in sources :

Example 16 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class FakeProjectFilesystem method createJavaOnlyFilesystem.

public static ProjectFilesystem createJavaOnlyFilesystem(String rootPath) {
    boolean isWindows = Platform.detect() == Platform.WINDOWS;
    Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix();
    rootPath = isWindows ? "C:" + rootPath : rootPath;
    FileSystem vfs = Jimfs.newFileSystem(configuration);
    Path root = vfs.getPath(rootPath);
    try {
        Files.createDirectories(root);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new ProjectFilesystem(root) {

        @Override
        public Path resolve(Path path) {
            // Avoid resolving paths from different Java FileSystems.
            return super.resolve(path.toString());
        }
    };
}
Also used : Path(java.nio.file.Path) Configuration(com.google.common.jimfs.Configuration) FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 17 with FileSystem

use of java.nio.file.FileSystem in project neo4j by neo4j.

the class SpecSuiteResources method unpackResources.

private static void unpackResources(Class<?> klass) {
    String specSuiteName = getSpecSuiteName(klass);
    File featuresDirectory = createTargetDirectory(specSuiteName, "features");
    File graphsDirectory = createTargetDirectory(specSuiteName, "graphs");
    URI uri;
    try {
        uri = getResourceUri(klass);
    } catch (URISyntaxException e) {
        throw new IllegalStateException("Failed to find resources for TCK feature files in JAR!", e);
    }
    try {
        try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
            Path path = fileSystem.getPath("/");
            findAndUnpackTo(fileSystem, path, featuresDirectory, graphsDirectory);
        } catch (IllegalArgumentException e) {
            // This is a workaround as the JDK doesn't give us a filesystem for subdirectories
            if ("file".equals(uri.getScheme())) {
                Path path = new File(uri.getPath()).toPath();
                findAndUnpackTo(FileSystems.getDefault(), path, featuresDirectory, graphsDirectory);
            } else {
                throw e;
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Unexpected error while unpacking Cypher TCK feature files", e);
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File) URI(java.net.URI)

Example 18 with FileSystem

use of java.nio.file.FileSystem in project dex2jar by pxb1988.

the class Jar2JasminCmd method doCommandLine.

@Override
protected void doCommandLine() throws Exception {
    if (remainingArgs.length != 1) {
        usage();
        return;
    }
    Path jar = new File(remainingArgs[0]).toPath().toAbsolutePath();
    if (!Files.exists(jar)) {
        System.err.println(jar + " is not exists");
        usage();
        return;
    }
    if (output == null) {
        output = new File(getBaseName(jar) + "-jar2jasmin/").toPath();
    }
    if (Files.exists(output) && !forceOverwrite) {
        System.err.println(output + " exists, use --force to overwrite");
        usage();
        return;
    }
    System.out.println("disassemble " + jar + " -> " + output);
    if (!output.toString().endsWith(".jar") && !output.toString().endsWith(".apk")) {
        disassemble0(jar, output);
    } else {
        try (FileSystem fs = createZip(output)) {
            disassemble0(jar, fs.getPath("/"));
        }
    }
}
Also used : FileSystem(java.nio.file.FileSystem)

Example 19 with FileSystem

use of java.nio.file.FileSystem in project dex2jar by pxb1988.

the class BaksmaliTest method dotest.

private void dotest(Path f) throws Exception {
    Path smali0 = new File("target/" + f.getFileName() + "-smali0.zip").toPath();
    try (FileSystem fs0 = BaseCmd.createZip(smali0)) {
        Baksmali.from(f).to(fs0.getPath("/"));
    }
    Path smali1 = new File("target/" + f.getFileName() + "-smali1.zip").toPath();
    try (FileSystem fs0 = BaseCmd.openZip(smali0);
        FileSystem fs1 = BaseCmd.createZip(smali1)) {
        BaksmaliDumper baksmaliDumper = new BaksmaliDumper();
        BaksmaliDexFileVisitor v = new BaksmaliDexFileVisitor(fs1.getPath("/"), baksmaliDumper);
        Smali.smali(fs0.getPath("/"), v);
    }
}
Also used : Path(java.nio.file.Path) BaksmaliDumper(com.googlecode.d2j.smali.BaksmaliDumper) FileSystem(java.nio.file.FileSystem) BaksmaliDexFileVisitor(com.googlecode.d2j.smali.BaksmaliDexFileVisitor) File(java.io.File)

Example 20 with FileSystem

use of java.nio.file.FileSystem in project dex2jar by pxb1988.

the class ApkSign method doCommandLine.

@Override
protected void doCommandLine() throws Exception {
    if (remainingArgs.length != 1) {
        usage();
        return;
    }
    Path apkIn = new File(remainingArgs[0]).toPath();
    if (!Files.exists(apkIn)) {
        System.err.println(apkIn + " is not exists");
        usage();
        return;
    }
    if (output == null) {
        if (Files.isDirectory(apkIn)) {
            output = new File(apkIn.getFileName() + "-signed.apk").toPath();
        } else {
            output = new File(getBaseName(apkIn.getFileName().toString()) + "-signed.apk").toPath();
        }
    }
    if (Files.exists(output) && !forceOverwrite) {
        System.err.println(output + " exists, use --force to overwrite");
        usage();
        return;
    }
    Path tmp = null;
    try {
        final Path realJar;
        if (Files.isDirectory(apkIn)) {
            realJar = Files.createTempFile("d2j", ".jar");
            tmp = realJar;
            System.out.println("zipping " + apkIn + " -> " + realJar);
            try (FileSystem fs = createZip(realJar)) {
                final Path outRoot = fs.getPath("/");
                walkJarOrDir(apkIn, new FileVisitorX() {

                    @Override
                    public void visitFile(Path file, String relative) throws IOException {
                        Path target = outRoot.resolve(relative);
                        createParentDirectories(target);
                        Files.copy(file, target);
                    }
                });
            }
        } else {
            realJar = apkIn;
        }
        AbstractJarSign signer;
        if (tiny) {
            signer = new TinySignImpl();
        } else {
            try {
                CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
                X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(ApkSign.class.getResourceAsStream("ApkSign.cer"));
                KeyFactory rSAKeyFactory = KeyFactory.getInstance("RSA");
                PrivateKey privateKey = rSAKeyFactory.generatePrivate(new PKCS8EncodedKeySpec(ZipUtil.toByteArray(ApkSign.class.getResourceAsStream("ApkSign.private"))));
                signer = new SunJarSignImpl(cert, privateKey);
            } catch (Exception cnfe) {
                signer = new TinySignImpl();
            }
        }
        signer.sign(apkIn.toFile(), output.toFile());
        System.out.println("sign " + realJar + " -> " + output);
    } finally {
        if (tmp != null) {
            Files.deleteIfExists(tmp);
        }
    }
}
Also used : Path(java.nio.file.Path) SunJarSignImpl(com.googlecode.d2j.signapk.SunJarSignImpl) PrivateKey(java.security.PrivateKey) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) IOException(java.io.IOException) AbstractJarSign(com.googlecode.d2j.signapk.AbstractJarSign) FileSystem(java.nio.file.FileSystem) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) File(java.io.File) KeyFactory(java.security.KeyFactory) TinySignImpl(com.googlecode.d2j.signapk.TinySignImpl)

Aggregations

FileSystem (java.nio.file.FileSystem)156 Path (java.nio.file.Path)109 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 URI (java.net.URI)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4