@Override public Map<String, Object> readAttributes(final Path path, final String attributes, final LinkOption... options) throws UnsupportedOperationException, IllegalArgumentException, IOException, SecurityException { checkNotNull("path", path); checkNotEmpty("attributes", attributes); final String[] s = split(attributes); if (s[0].length() == 0) { throw new IllegalArgumentException(attributes); } final FlexibleFileAttributeView view = getFileAttributeView(toPathImpl(path), s[0], options); if (view == null) { throw new UnsupportedOperationException("View '" + s[0] + "' not available"); } return view.readAttributes(s[1].split(",")); }
@Override public void setAttribute(final Path path, final String attribute, final Object value, final LinkOption... options) throws UnsupportedOperationException, IllegalArgumentException, ClassCastException, IOException, SecurityException { checkNotNull("path", path); checkNotEmpty("attributes", attribute); final String[] s = split(attribute); if (s[0].length() == 0) { throw new IllegalArgumentException(attribute); } final FlexibleFileAttributeView view = getFileAttributeView(toPathImpl(path), s[0], options); if (view == null) { throw new UnsupportedOperationException("View '" + s[0] + "' not available"); } view.setAttribute(s[1], value); }
return map; } else { final ExtendedAttributeView view = getFileAttributeView(toPathImpl(path), s[0], options);
final JGitVersionAttributeView view = getFileAttributeView(path, JGitVersionAttributeView.class, options); return (A) view.readAttributes(); } else if (type == HiddenAttributes.class) { final JGitHiddenAttributeView view = getFileAttributeView(path, JGitHiddenAttributeView.class, options); return (A) view.readAttributes(); } else if (type == BasicFileAttributesImpl.class || type == BasicFileAttributes.class) { final JGitBasicAttributeView view = getFileAttributeView(path, JGitBasicAttributeView.class, options);
@Test public void accessOldVersions() throws Exception { final URI newRepo = URI.create("git://old-versions-test-repo"); final FileSystem fs = provider.newFileSystem(newRepo, new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_INIT, "true"); }}); assertThat(fs).isNotNull(); for (int i = 0; i < 5; i++) { final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my cool content" + i).getBytes()); outStream.close(); } final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final JGitVersionAttributeView attrs = provider.getFileAttributeView(path, JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(5); for (int i = 0; i < 5; i++) { final Path oldPath = provider.getPath(URI.create("git://" + attrs.readAttributes().history().records().get(i).id() + "@old-versions-test-repo/some/path/myfile.txt")); final InputStream stream = provider.newInputStream(oldPath); assertNotNull(stream); final String content = new Scanner(stream).useDelimiter("\\A").next(); assertEquals("my cool content" + i, content); } }
@Test public void accessOldVersions() throws Exception { final URI newRepo = URI.create("git://old-versions-test-repo"); final FileSystem fs = provider.newFileSystem(newRepo, new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_INIT, "true"); }}); assertThat(fs).isNotNull(); for (int i = 0; i < 5; i++) { final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my cool content" + i).getBytes()); outStream.close(); } final Path path = provider.getPath(URI.create("git://old-versions-test-repo/some/path/myfile.txt")); final JGitVersionAttributeView attrs = provider.getFileAttributeView(path, JGitVersionAttributeView.class); assertThat(attrs.readAttributes().history().records().size()).isEqualTo(5); for (int i = 0; i < 5; i++) { final Path oldPath = provider.getPath(URI.create("git://" + attrs.readAttributes().history().records().get(i).id() + "@old-versions-test-repo/some/path/myfile.txt")); final InputStream stream = provider.newInputStream(oldPath); assertNotNull(stream); final String content = new Scanner(stream).useDelimiter("\\A").next(); assertEquals("my cool content" + i, content); } }
throw new IllegalArgumentException(attribute); final ExtendedAttributeView view = getFileAttributeView(toPathImpl(path), s[0], options);
final JGitVersionAttributeView attrs = provider.getFileAttributeView(path.getRoot(), JGitVersionAttributeView.class);
final JGitVersionAttributeView attrs = provider.getFileAttributeView(path.getRoot(), JGitVersionAttributeView.class);
@Override public <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) throws NoSuchFileException, UnsupportedOperationException, IOException, SecurityException { checkNotNull("path", path); checkNotNull("type", type); final JGitPathImpl gPath = toPathImpl(path); final Pair<PathType, ObjectId> pathResult = checkPath(gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath()); if (pathResult.getK1().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } if (type == BasicFileAttributes.class || type == JGitFileAttributes.class) { final JGitFileAttributeView view = getFileAttributeView(path, JGitFileAttributeView.class, options); return (A) view.readAttributes(); } return null; }
outStream3.close(); final JGitVersionAttributeView attrs = provider.getFileAttributeView(path3, JGitVersionAttributeView.class); provider.getFileAttributeView(provider.getPath(URI.create("git://user_branch@getfileattriview-test-repo/not_exists.txt")), BasicFileAttributeView.class); failBecauseExceptionWasNotThrown(NoSuchFileException.class); assertThat(provider.getFileAttributeView(path3, MyInvalidFileAttributeView.class)).isNull(); final BasicFileAttributeView attrsRoot = provider.getFileAttributeView(rootPath, BasicFileAttributeView.class); final HiddenAttributeView extendedAttrs = provider.getFileAttributeView(prRootPath, HiddenAttributeView.class);
outStream3.close(); final JGitVersionAttributeView attrs = provider.getFileAttributeView(path3, JGitVersionAttributeView.class); provider.getFileAttributeView(provider.getPath(URI.create("git://user_branch@getfileattriview-test-repo/not_exists.txt")), BasicFileAttributeView.class); failBecauseExceptionWasNotThrown(NoSuchFileException.class); assertThat(provider.getFileAttributeView(path3, MyInvalidFileAttributeView.class)).isNull(); final BasicFileAttributeView attrsRoot = provider.getFileAttributeView(rootPath, BasicFileAttributeView.class); final HiddenAttributeView extendedAttrs = provider.getFileAttributeView(prRootPath, HiddenAttributeView.class);