< prev index next >

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java

Print this page
rev 52310 : 8213031: (zipfs) Add support for POSIX file permissions

*** 1,7 **** /* ! * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 23,43 **** * questions. */ package jdk.nio.zipfs; - import java.nio.file.attribute.*; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; ! /* ! * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ ! ! class ZipFileAttributeView implements BasicFileAttributeView ! { private static enum AttrID { size, creationTime, lastAccessTime, lastModifiedTime, --- 23,48 ---- * questions. */ package jdk.nio.zipfs; import java.io.IOException; + import java.nio.file.attribute.BasicFileAttributeView; + import java.nio.file.attribute.FileAttributeView; + import java.nio.file.attribute.FileTime; + import java.nio.file.attribute.GroupPrincipal; + import java.nio.file.attribute.PosixFileAttributeView; + import java.nio.file.attribute.PosixFilePermission; + import java.nio.file.attribute.UserPrincipal; import java.util.LinkedHashMap; import java.util.Map; + import java.util.Set; ! /** ! * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ ! class ZipFileAttributeView implements PosixFileAttributeView { private static enum AttrID { size, creationTime, lastAccessTime, lastModifiedTime,
*** 46,94 **** isSymbolicLink, isOther, fileKey, compressedSize, crc, ! method }; private final ZipPath path; ! private final boolean isZipView; ! private ZipFileAttributeView(ZipPath path, boolean isZipView) { this.path = path; ! this.isZipView = isZipView; } @SuppressWarnings("unchecked") // Cast to V static <V extends FileAttributeView> V get(ZipPath path, Class<V> type) { if (type == null) throw new NullPointerException(); if (type == BasicFileAttributeView.class) ! return (V)new ZipFileAttributeView(path, false); if (type == ZipFileAttributeView.class) ! return (V)new ZipFileAttributeView(path, true); return null; } static ZipFileAttributeView get(ZipPath path, String type) { if (type == null) throw new NullPointerException(); if (type.equals("basic")) ! return new ZipFileAttributeView(path, false); if (type.equals("zip")) ! return new ZipFileAttributeView(path, true); return null; } @Override public String name() { ! return isZipView ? "zip" : "basic"; } ! public ZipFileAttributes readAttributes() throws IOException ! { return path.getAttributes(); } @Override public void setTimes(FileTime lastModifiedTime, --- 51,117 ---- isSymbolicLink, isOther, fileKey, compressedSize, crc, ! method, ! permissions }; + private static enum ViewType { + zip, + posix, + basic + } + private final ZipPath path; ! private final ViewType type; ! private ZipFileAttributeView(ZipPath path, ViewType type) { this.path = path; ! this.type = type; } @SuppressWarnings("unchecked") // Cast to V static <V extends FileAttributeView> V get(ZipPath path, Class<V> type) { if (type == null) throw new NullPointerException(); if (type == BasicFileAttributeView.class) ! return (V)new ZipFileAttributeView(path, ViewType.basic); ! if (type == PosixFileAttributeView.class) ! return (V)new ZipFileAttributeView(path, ViewType.posix); if (type == ZipFileAttributeView.class) ! return (V)new ZipFileAttributeView(path, ViewType.zip); return null; } static ZipFileAttributeView get(ZipPath path, String type) { if (type == null) throw new NullPointerException(); if (type.equals("basic")) ! return new ZipFileAttributeView(path, ViewType.basic); ! if (type.equals("posix")) ! return new ZipFileAttributeView(path, ViewType.posix); if (type.equals("zip")) ! return new ZipFileAttributeView(path, ViewType.zip); return null; } @Override public String name() { ! switch (type) { ! case zip: ! return "zip"; ! case posix: ! return "posix"; ! case basic: ! default: ! return "basic"; ! } } ! public ZipFileAttributes readAttributes() throws IOException { return path.getAttributes(); } @Override public void setTimes(FileTime lastModifiedTime,
*** 102,116 **** void setAttribute(String attribute, Object value) throws IOException { try { if (AttrID.valueOf(attribute) == AttrID.lastModifiedTime) ! setTimes ((FileTime)value, null, null); if (AttrID.valueOf(attribute) == AttrID.lastAccessTime) ! setTimes (null, (FileTime)value, null); if (AttrID.valueOf(attribute) == AttrID.creationTime) ! setTimes (null, null, (FileTime)value); return; } catch (IllegalArgumentException x) {} throw new UnsupportedOperationException("'" + attribute + "' is unknown or read-only attribute"); } --- 125,139 ---- void setAttribute(String attribute, Object value) throws IOException { try { if (AttrID.valueOf(attribute) == AttrID.lastModifiedTime) ! setTimes((FileTime)value, null, null); if (AttrID.valueOf(attribute) == AttrID.lastAccessTime) ! setTimes(null, (FileTime)value, null); if (AttrID.valueOf(attribute) == AttrID.creationTime) ! setTimes(null, null, (FileTime)value); return; } catch (IllegalArgumentException x) {} throw new UnsupportedOperationException("'" + attribute + "' is unknown or read-only attribute"); }
*** 156,175 **** case isOther: return zfas.isOther(); case fileKey: return zfas.fileKey(); case compressedSize: ! if (isZipView) return zfas.compressedSize(); break; case crc: ! if (isZipView) return zfas.crc(); break; case method: ! if (isZipView) return zfas.method(); break; } return null; } } --- 179,227 ---- case isOther: return zfas.isOther(); case fileKey: return zfas.fileKey(); case compressedSize: ! if (type == ViewType.zip) return zfas.compressedSize(); break; case crc: ! if (type == ViewType.zip) return zfas.crc(); break; case method: ! if (type == ViewType.zip) return zfas.method(); break; + case permissions: + if (type == ViewType.zip || type == ViewType.posix) { + try { + return zfas.permissions(); + } catch (UnsupportedOperationException e) { + return null; + } + } + break; } return null; } + + @Override + public UserPrincipal getOwner() throws IOException { + throw new UnsupportedOperationException("ZipFileSystem does not support getOwner."); + } + + @Override + public void setOwner(UserPrincipal owner) throws IOException { + throw new UnsupportedOperationException("ZipFileSystem does not support setOwner."); + } + + @Override + public void setPermissions(Set<PosixFilePermission> perms) throws IOException { + readAttributes().setPermissions(perms); + } + + @Override + public void setGroup(GroupPrincipal group) throws IOException { + throw new UnsupportedOperationException("ZipFileSystem does not support setGroup."); + } }
< prev index next >