use of java.nio.file.attribute.BasicFileAttributes in project jimfs by google.
the class AttributeServiceTest method testReadAttributes_asObject.
@Test
public void testReadAttributes_asObject() {
File file = Directory.create(0);
service.setInitialAttributes(file);
BasicFileAttributes basicAttrs = service.readAttributes(file, BasicFileAttributes.class);
assertThat(basicAttrs.fileKey()).isEqualTo(0);
assertThat(basicAttrs.isDirectory()).isTrue();
assertThat(basicAttrs.isRegularFile()).isFalse();
TestAttributes testAttrs = service.readAttributes(file, TestAttributes.class);
assertThat(testAttrs.foo()).isEqualTo("hello");
assertThat(testAttrs.bar()).isEqualTo(0);
assertThat(testAttrs.baz()).isEqualTo(1);
file.setAttribute("test", "baz", 100);
assertThat(service.readAttributes(file, TestAttributes.class).baz()).isEqualTo(100);
}
use of java.nio.file.attribute.BasicFileAttributes in project jdk8u_jdk by JetBrains.
the class TestWsImport method main.
public static void main(String[] args) throws IOException {
String javaHome = System.getProperty("java.home");
if (javaHome.endsWith("jre")) {
javaHome = new File(javaHome).getParent();
}
String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";
if (System.getProperty("os.name").startsWith("Windows")) {
wsimport = wsimport.concat(".exe");
}
Endpoint endpoint = Endpoint.create(new TestService());
HttpServer httpServer = null;
try {
// Manually create HttpServer here using ephemeral address for port
// so as to not end up with attempt to bind to an in-use port
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
HttpContext httpContext = httpServer.createContext("/hello");
int port = httpServer.getAddress().getPort();
System.out.println("port = " + port);
httpServer.start();
endpoint.publish(httpContext);
String address = "http://localhost:" + port + "/hello";
Service service = Service.create(new URL(address + "?wsdl"), new QName("http://test/jaxws/sample/", "TestService"));
String[] wsargs = { wsimport, "-p", "wstest", "-J-Djavax.xml.accessExternalSchema=all", "-J-Dcom.sun.tools.internal.ws.Invoker.noSystemProxies=true", address + "?wsdl", "-clientjar", "wsjar.jar" };
ProcessBuilder pb = new ProcessBuilder(wsargs);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = r.readLine();
while (s != null) {
System.out.println(s.trim());
s = r.readLine();
}
p.waitFor();
p.destroy();
try (JarFile jarFile = new JarFile("wsjar.jar")) {
for (Enumeration em = jarFile.entries(); em.hasMoreElements(); ) {
String fileName = em.nextElement().toString();
if (fileName.contains("\\")) {
throw new RuntimeException("\"\\\" character detected in jar file: " + fileName);
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} finally {
endpoint.stop();
if (httpServer != null) {
httpServer.stop(0);
}
Path p = Paths.get("wsjar.jar");
Files.deleteIfExists(p);
p = Paths.get("wstest");
if (Files.exists(p)) {
try {
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return CONTINUE;
} else {
throw exc;
}
}
});
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
use of java.nio.file.attribute.BasicFileAttributes in project jdk8u_jdk by JetBrains.
the class Test method deleteGeneratedFiles.
private static void deleteGeneratedFiles() {
Path p = Paths.get("..", "classes", "javax", "xml", "ws", "xsanymixed", "org");
System.out.println("performing cleanup, deleting wsdl compilation result: " + p.toFile().getAbsolutePath());
if (Files.exists(p)) {
try {
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
System.out.println("deleting file [" + file.toFile().getAbsoluteFile() + "]");
Files.delete(file);
return CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
System.out.println("deleting dir [" + dir.toFile().getAbsoluteFile() + "]");
if (exc == null) {
Files.delete(dir);
return CONTINUE;
} else {
throw exc;
}
}
});
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
use of java.nio.file.attribute.BasicFileAttributes in project OpenAM by OpenRock.
the class DefaultDebugRecorder method delete.
/**
* Delete a file
*
* @param file to delete
* @throws IOException
*/
private void delete(String file) throws IOException {
Path start = Paths.get(file);
Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
// directory iteration failed
throw e;
}
}
});
}
use of java.nio.file.attribute.BasicFileAttributes in project OpenAM by OpenRock.
the class ZipUtils method generateZip.
/**
* Generate a zip
*
* Due to a bug in Java 7 corrected in Java 8 http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7156873
* srcFolder and outputZip can't be URL encoded if you're using java 7.
*
* @param srcFolder source folder
* @param outputZip zip folder
* @return the list of files that were included in the archive.
* @throws IOException if an error occurs creating the zip archive.
* @throws URISyntaxException if an error occurs creating the zip archive.
*/
public static List<String> generateZip(String srcFolder, String outputZip) throws IOException, URISyntaxException {
final Path targetZip = Paths.get(outputZip);
final Path sourceDir = Paths.get(srcFolder);
final URI uri = new URI("jar", URLDecoder.decode(targetZip.toUri().toString(), "UTF-8"), null);
final List<String> files = new ArrayList<>();
try (FileSystem zipfs = FileSystems.newFileSystem(uri, singletonMap("create", "true"))) {
Files.walkFileTree(sourceDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// In case the target zip is being created in the folder being zipped (e.g. Fedlet), ignore it.
if (targetZip.equals(file)) {
return FileVisitResult.CONTINUE;
}
Path target = zipfs.getPath(sourceDir.relativize(file).toString());
if (target.getParent() != null) {
Files.createDirectories(target.getParent());
}
Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
files.add(file.toString());
return FileVisitResult.CONTINUE;
}
});
}
return files;
}
Aggregations