@Override public void setUp() throws IOException { rootDir = Jimfs.newFileSystem(Configuration.unix()).getPath("/tmp"); Files.createDirectory(rootDir); }
/** * Returns a default configuration appropriate to the current operating system. * * <p>More specifically, if the operating system is Windows, {@link Configuration#windows()} is * returned; if the operating system is Mac OS X, {@link Configuration#osX()} is returned; * otherwise, {@link Configuration#unix()} is returned. * * <p>This is the configuration used by the {@code Jimfs.newFileSystem} methods that do not take * a {@code Configuration} parameter. * * @since 1.1 */ public static Configuration forCurrentPlatform() { String os = System.getProperty("os.name"); if (os.contains("Windows")) { return windows(); } else if (os.contains("OS X")) { return osX(); } else { return unix(); } }
private ErrorProneInMemoryFileManager(Optional<Class<?>> clazz) { super(new Context(), /* register= */ false, UTF_8); this.fileSystem = Jimfs.newFileSystem(Configuration.unix()); this.clazz = clazz; }
@Parameters(name = "os = {0}") public static Collection<Object[]> data() { return Arrays.asList( new Object[][] { {"Unix", Configuration.unix(), "/usr/home/android/sdk", ""}, {"Windows", Configuration.windows(), "C:\\android\\sdk", ".exe"}, {"OS X", Configuration.osX(), "/Users/home/android/sdk", ""} }); }
public void testByteSource_size_ofSymlinkToRegularFile() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path file = fs.getPath("file"); Files.write(file, new byte[10]); Path link = fs.getPath("link"); Files.createSymbolicLink(link, file); ByteSource source = MoreFiles.asByteSource(link); assertEquals(10L, (long) source.sizeIfKnown().get()); assertEquals(10L, source.size()); } }
private static FileSystem createFileSystem() { // TODO: use the current platform configuration and get rid of all the agnostic path stuff. Configuration config = Configuration.unix(); config = config.toBuilder() .setWorkingDirectory("/") .setAttributeViews("posix") .build(); return Jimfs.newFileSystem(config); }
/** * Returns a default configuration appropriate to the current operating system. * * <p>More specifically, if the operating system is Windows, {@link Configuration#windows()} is * returned; if the operating system is Mac OS X, {@link Configuration#osX()} is returned; * otherwise, {@link Configuration#unix()} is returned. * * <p>This is the configuration used by the {@code Jimfs.newFileSystem} methods that do not take * a {@code Configuration} parameter. * * @since 1.1 */ public static Configuration forCurrentPlatform() { String os = System.getProperty("os.name"); if (os.contains("Windows")) { return windows(); } else if (os.contains("OS X")) { return osX(); } else { return unix(); } }
public void testByteSource_size_ofDirectory() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path dir = fs.getPath("dir"); Files.createDirectory(dir); ByteSource source = MoreFiles.asByteSource(dir); assertThat(source.sizeIfKnown()).isAbsent(); try { source.size(); fail(); } catch (IOException expected) { } } }
public void testByteSource_size_ofSymlinkToRegularFile_nofollowLinks() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path file = fs.getPath("file"); Files.write(file, new byte[10]); Path link = fs.getPath("link"); Files.createSymbolicLink(link, file); ByteSource source = MoreFiles.asByteSource(link, NOFOLLOW_LINKS); assertThat(source.sizeIfKnown()).isAbsent(); try { source.size(); fail(); } catch (IOException expected) { } } }
public void testByteSource_size_ofSymlinkToDirectory() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path dir = fs.getPath("dir"); Files.createDirectory(dir); Path link = fs.getPath("link"); Files.createSymbolicLink(link, dir); ByteSource source = MoreFiles.asByteSource(link); assertThat(source.sizeIfKnown()).isAbsent(); try { source.size(); fail(); } catch (IOException expected) { } } }
public void testEqual_links() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path fooPath = fs.getPath("foo"); MoreFiles.asCharSink(fooPath, UTF_8).write("foo"); Path fooSymlink = fs.getPath("symlink"); Files.createSymbolicLink(fooSymlink, fooPath); Path fooHardlink = fs.getPath("hardlink"); Files.createLink(fooHardlink, fooPath); assertThat(MoreFiles.equal(fooPath, fooSymlink)).isTrue(); assertThat(MoreFiles.equal(fooPath, fooHardlink)).isTrue(); assertThat(MoreFiles.equal(fooSymlink, fooHardlink)).isTrue(); } }
public void testEqual() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path fooPath = fs.getPath("foo"); Path barPath = fs.getPath("bar"); MoreFiles.asCharSink(fooPath, UTF_8).write("foo"); MoreFiles.asCharSink(barPath, UTF_8).write("barbar"); assertThat(MoreFiles.equal(fooPath, barPath)).isFalse(); assertThat(MoreFiles.equal(fooPath, fooPath)).isTrue(); assertThat(MoreFiles.asByteSource(fooPath).contentEquals(MoreFiles.asByteSource(fooPath))) .isTrue(); Path fooCopy = Files.copy(fooPath, fs.getPath("fooCopy")); assertThat(Files.isSameFile(fooPath, fooCopy)).isFalse(); assertThat(MoreFiles.equal(fooPath, fooCopy)).isTrue(); MoreFiles.asCharSink(fooCopy, UTF_8).write("boo"); assertThat(MoreFiles.asByteSource(fooPath).size()) .isEqualTo(MoreFiles.asByteSource(fooCopy).size()); assertThat(MoreFiles.equal(fooPath, fooCopy)).isFalse(); // should also assert that a Path that erroneously reports a size 0 can still be compared, // not sure how to do that with the Path API } }
@Test public void profileInZip() throws IOException { FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix()); Files.createDirectories(fileSystem.getPath("/source")); Path zip = fileSystem.getPath("/source/protos.zip"); ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(zip)); writeFile(zipOutputStream, "a/b/message.proto", "" + "package a.b;\n" + "message Message {" + "}"); writeFile(zipOutputStream, "a/b/android.wire", "" + "syntax = \"wire2\";\n" + "package a.b;\n" + "import \"a/b/message.proto\";\n" + "type a.b.Message {\n" + " target java.lang.Object using com.example.Message#ADAPTER;\n" + "}"); zipOutputStream.close(); Schema schema = new SchemaLoader() .addSource(zip) .load(); Profile profile = new ProfileLoader(fileSystem, "android") .schema(schema) .load(); ProtoType message = ProtoType.get("a.b.Message"); assertThat(profile.getTarget(message)).isEqualTo(ClassName.OBJECT); assertThat(profile.getAdapter(message)).isEqualTo( new AdapterConstant("com.example.Message#ADAPTER")); }
public static FileSystem get() { if (fileSystemThreadLocal.get() == null) { fileSystemThreadLocal.set(Jimfs.newFileSystem(Configuration.unix())); } return fileSystemThreadLocal.get(); }
@Override void runWithPaths(String inputPath, String outputhPath) { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { buildAndPrintResult(inputPath, fs); } catch (IOException ioe) { throw new IllegalStateException(ioe); } }
public AbstractSourceInstance(Properties properties) { this.properties = properties; List<FileSystemProvider> list = JimfsFileSystemProvider.installedProviders(); try { URI uri = new URI("jimfs", "vefa", null, null); ImmutableMap<String, ?> env = ImmutableMap.of("config", Configuration.unix()); for (FileSystemProvider provider : list) if (provider instanceof JimfsFileSystemProvider) fileSystem = provider.newFileSystem(uri, env); if (fileSystem == null) fileSystem = new JimfsFileSystemProvider().newFileSystem(uri, env); } catch (Exception e) { throw new RuntimeException("Unable to create VEFA Validator instance", e); } }