@Test public void test() throws Exception { FileSystem from = new DummyFileSystemProvider().getFileSystem(null); Path root = from.getRootDirectories().iterator().next(); for (Path p : from.provider().newDirectoryStream(root, null)) { System.out.println(p); } }
public void testStartsForZip() throws Exception { URI uri = URI.create("jar:file:/zipfstest.zip!/BAR"); Map<String, String> env = new HashMap<>(); env.put("create", "true"); System.out.println(uri.getScheme()); // com.sun.nio.zipfs.ZipFileSystemProvider z; FileSystem zipfs = FileSystems.newFileSystem(uri, env); Path p = zipfs.provider().getPath(uri); System.out.println(p.toString()); Path p1 = zipfs.provider().getPath(URI.create("jar:file:/zipfstest.zip!/BAR/PAR")); System.out.println(p1.startsWith(p)); // should be true Path p2 = zipfs.provider().getPath(URI.create("jar:file:/zipfstest.zip!/PAR/PAR1")); System.out.println(p2.startsWith(p)); // should be false // checking problem when mRoot = jar:file:/zipfstest.zip!/BAR/PAR, fileSystem = // jar:file:/zipfstest.zip // and received "/BAR" as getPath function Path p3 = p.getFileSystem().getPath("/PAR"); System.out.println(p2.resolve("RAR").startsWith(p2)); // should be true System.out.println(p2.resolve("/RAR").startsWith(p2)); // should be false System.out.println(p2.getFileSystem().getPath("/PAR2", "PAR3", "PAR4").toAbsolutePath()); System.out.println(p2.startsWith(p2)); // should be true Path pathDir = Files.createDirectory(p3); System.out.println(Files.isDirectory(pathDir)); long longSize = 0xFFFFFFFFFFFFFFFFl; // Integer.MAX_VALUE; // longSize *= 2; int intSize = (int) longSize; System.out.println(longSize); System.out.println(intSize == longSize); // === testWindows(); testZIP(); // }
/** Filesystem ist trehad safe. */ @Test public void testFilesystemInfo() { FileSystem fileSystem = FileSystems.getDefault(); // som overloads // FileSystems.getFileSystem(); // FileSystems.newFileSystem(Path, ClassLoader) // default FS is always open assertTrue(fileSystem.isOpen()); assertFalse(fileSystem.isReadOnly()); // can be changed for example by inserting usb memory stick List<Path> rootDirectories = iterableToList(fileSystem.getRootDirectories()); assertEquals( Arrays.asList(Paths.get("C:\\"), Paths.get("D:\\"), Paths.get("E:\\")), rootDirectories); // fost of Files static methods delegate to this provider FileSystemProvider provider = fileSystem.provider(); assertNotNull(provider); }
public EdisonPinManager(short[] pins) { gpioPinInt = pins; gpio = new Path[pins.length]; gpioDirection = new Path[pins.length]; gpioValue = new Path[pins.length]; gpioPinString = new String[pins.length]; gpioDebugCurrentPinMux = new Path[pins.length]; // NOTE only needed for mode array FileSystem fileSystem = FileSystems.getDefault(); this.provider = fileSystem.provider(); int i = pins.length; StringBuilder sb = new StringBuilder(); sb.append("/sys/class/gpio/gpio"); int baseLen = sb.length(); while (--i >= 0) { if (pins[i] >= 0) { gpioPinString[i] = Integer.toString(pins[i]); gpioDebugCurrentPinMux[i] = fileSystem.getPath( "/sys/kernel/debug/gpio_debug/gpio" + gpioPinString[i] + "/current_pinmux"); sb.setLength(baseLen); sb.append(gpioPinString[i]); gpio[i] = fileSystem.getPath(sb.toString()); int withIdLen = sb.length(); sb.append("/direction"); gpioDirection[i] = fileSystem.getPath(sb.toString()); sb.setLength(withIdLen); sb.append("/value"); gpioValue[i] = fileSystem.getPath(sb.toString()); } } }
public static void testZIP() throws Exception { // ==== Testing ZIP filesystem === // two options to write - WRITE, WRITE + APPEND. Simple writes just rewrite current values URI uri = URI.create("jar:file:/test.zip!/test.txt"); Map<String, String> env = new HashMap<>(); env.put("create", "true"); FileSystem zipfs = FileSystems.newFileSystem(uri, env); Path pz = zipfs.provider().getPath(uri); SeekableByteChannel s = Files.newByteChannel( pz, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.APPEND); // , StandardOpenOption.APPEND); ByteBuffer bb = ByteBuffer.wrap("12345".getBytes()); // s.truncate(0);//clear file - unsupported // s.position(0);//start position - unsupported s.write(bb); bb.position(2); s.write(bb); // SeekableByteChannel s1 = Files.newByteChannel(pz, StandardOpenOption.WRITE, // StandardOpenOption.CREATE, StandardOpenOption.APPEND);//, StandardOpenOption.APPEND); // s1.write(ByteBuffer.wrap("bb".getBytes())); // s.close(); // s1.close(); s = Files.newByteChannel( pz, StandardOpenOption.READ, StandardOpenOption.CREATE); // , StandardOpenOption.APPEND); byte[] bbrb = new byte[(int) s.size()]; s.read(ByteBuffer.wrap(bbrb)); System.out.println(new String(bbrb)); // should be 12345345 s.close(); }