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());
}
};
}
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);
}
}
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("/"));
}
}
}
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);
}
}
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);
}
}
}
Aggregations