17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nio.zipfs;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.net.URI;
33 import java.nio.channels.FileChannel;
34 import java.nio.channels.SeekableByteChannel;
35 import java.nio.file.*;
36 import java.nio.file.DirectoryStream.Filter;
37 import java.nio.file.attribute.BasicFileAttributeView;
38 import java.nio.file.attribute.FileAttribute;
39 import java.nio.file.attribute.FileTime;
40 import java.util.Arrays;
41 import java.util.Iterator;
42 import java.util.Map;
43 import java.util.NoSuchElementException;
44 import java.util.Objects;
45 import java.util.Set;
46
47 import static java.nio.charset.StandardCharsets.UTF_8;
48 import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
49 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
50 import static java.nio.file.StandardOpenOption.CREATE;
51 import static java.nio.file.StandardOpenOption.READ;
52 import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
53 import static java.nio.file.StandardOpenOption.WRITE;
54
55 /**
56 * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal
57 */
58 final class ZipPath implements Path {
59
751 int colonPos = attribute.indexOf(':');
752 if (colonPos == -1) {
753 type = "basic";
754 attr = attribute;
755 } else {
756 type = attribute.substring(0, colonPos++);
757 attr = attribute.substring(colonPos);
758 }
759 ZipFileAttributeView view = ZipFileAttributeView.get(this, type);
760 if (view == null)
761 throw new UnsupportedOperationException("view <" + view + "> is not supported");
762 view.setAttribute(attr, value);
763 }
764
765 void setTimes(FileTime mtime, FileTime atime, FileTime ctime)
766 throws IOException
767 {
768 zfs.setTimes(getResolvedPath(), mtime, atime, ctime);
769 }
770
771 Map<String, Object> readAttributes(String attributes, LinkOption... options)
772 throws IOException
773
774 {
775 String view = null;
776 String attrs = null;
777 int colonPos = attributes.indexOf(':');
778 if (colonPos == -1) {
779 view = "basic";
780 attrs = attributes;
781 } else {
782 view = attributes.substring(0, colonPos++);
783 attrs = attributes.substring(colonPos);
784 }
785 ZipFileAttributeView zfv = ZipFileAttributeView.get(this, view);
786 if (zfv == null) {
787 throw new UnsupportedOperationException("view not supported");
788 }
789 return zfv.readAttributes(attrs);
790 }
791
792 FileStore getFileStore() throws IOException {
793 // each ZipFileSystem only has one root (as requested for now)
918 // create directory or file
919 target.createDirectory();
920 } else {
921 InputStream is = zfs.newInputStream(getResolvedPath());
922 try {
923 OutputStream os = target.newOutputStream();
924 try {
925 byte[] buf = new byte[8192];
926 int n = 0;
927 while ((n = is.read(buf)) != -1) {
928 os.write(buf, 0, n);
929 }
930 } finally {
931 os.close();
932 }
933 } finally {
934 is.close();
935 }
936 }
937 if (copyAttrs) {
938 BasicFileAttributeView view =
939 ZipFileAttributeView.get(target, BasicFileAttributeView.class);
940 try {
941 view.setTimes(zfas.lastModifiedTime(),
942 zfas.lastAccessTime(),
943 zfas.creationTime());
944 } catch (IOException x) {
945 // rollback?
946 try {
947 target.delete();
948 } catch (IOException ignore) { }
949 throw x;
950 }
951 }
952 }
953
954 private static int decode(char c) {
955 if ((c >= '0') && (c <= '9'))
956 return c - '0';
957 if ((c >= 'a') && (c <= 'f'))
958 return c - 'a' + 10;
959 if ((c >= 'A') && (c <= 'F'))
960 return c - 'A' + 10;
961 assert false;
962 return -1;
963 }
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nio.zipfs;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.net.URI;
33 import java.nio.channels.FileChannel;
34 import java.nio.channels.SeekableByteChannel;
35 import java.nio.file.*;
36 import java.nio.file.DirectoryStream.Filter;
37 import java.nio.file.attribute.FileAttribute;
38 import java.nio.file.attribute.FileTime;
39 import java.nio.file.attribute.PosixFilePermission;
40 import java.util.Arrays;
41 import java.util.Iterator;
42 import java.util.Map;
43 import java.util.NoSuchElementException;
44 import java.util.Objects;
45 import java.util.Set;
46
47 import static java.nio.charset.StandardCharsets.UTF_8;
48 import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
49 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
50 import static java.nio.file.StandardOpenOption.CREATE;
51 import static java.nio.file.StandardOpenOption.READ;
52 import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
53 import static java.nio.file.StandardOpenOption.WRITE;
54
55 /**
56 * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal
57 */
58 final class ZipPath implements Path {
59
751 int colonPos = attribute.indexOf(':');
752 if (colonPos == -1) {
753 type = "basic";
754 attr = attribute;
755 } else {
756 type = attribute.substring(0, colonPos++);
757 attr = attribute.substring(colonPos);
758 }
759 ZipFileAttributeView view = ZipFileAttributeView.get(this, type);
760 if (view == null)
761 throw new UnsupportedOperationException("view <" + view + "> is not supported");
762 view.setAttribute(attr, value);
763 }
764
765 void setTimes(FileTime mtime, FileTime atime, FileTime ctime)
766 throws IOException
767 {
768 zfs.setTimes(getResolvedPath(), mtime, atime, ctime);
769 }
770
771 void setPermissions(Set<PosixFilePermission> perms)
772 throws IOException
773 {
774 zfs.setPermissions(getResolvedPath(), perms);
775 }
776
777 Map<String, Object> readAttributes(String attributes, LinkOption... options)
778 throws IOException
779 {
780 String view = null;
781 String attrs = null;
782 int colonPos = attributes.indexOf(':');
783 if (colonPos == -1) {
784 view = "basic";
785 attrs = attributes;
786 } else {
787 view = attributes.substring(0, colonPos++);
788 attrs = attributes.substring(colonPos);
789 }
790 ZipFileAttributeView zfv = ZipFileAttributeView.get(this, view);
791 if (zfv == null) {
792 throw new UnsupportedOperationException("view not supported");
793 }
794 return zfv.readAttributes(attrs);
795 }
796
797 FileStore getFileStore() throws IOException {
798 // each ZipFileSystem only has one root (as requested for now)
923 // create directory or file
924 target.createDirectory();
925 } else {
926 InputStream is = zfs.newInputStream(getResolvedPath());
927 try {
928 OutputStream os = target.newOutputStream();
929 try {
930 byte[] buf = new byte[8192];
931 int n = 0;
932 while ((n = is.read(buf)) != -1) {
933 os.write(buf, 0, n);
934 }
935 } finally {
936 os.close();
937 }
938 } finally {
939 is.close();
940 }
941 }
942 if (copyAttrs) {
943 ZipFileAttributeView view =
944 ZipFileAttributeView.get(target, ZipFileAttributeView.class);
945 try {
946 view.setTimes(zfas.lastModifiedTime(),
947 zfas.lastAccessTime(),
948 zfas.creationTime());
949 // copy permissions if available
950 try {
951 view.setPermissions(zfas.permissions());
952 } catch (UnsupportedOperationException uoe) {
953 // the current entry may have no permissions.
954 }
955 } catch (IOException x) {
956 // rollback?
957 try {
958 target.delete();
959 } catch (IOException ignore) { }
960 throw x;
961 }
962 }
963 }
964
965 private static int decode(char c) {
966 if ((c >= '0') && (c <= '9'))
967 return c - '0';
968 if ((c >= 'a') && (c <= 'f'))
969 return c - 'a' + 10;
970 if ((c >= 'A') && (c <= 'F'))
971 return c - 'A' + 10;
972 assert false;
973 return -1;
974 }
|