8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
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 package jdk.internal.jrtfs;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31 import java.net.URI;
32 import java.net.URISyntaxException;
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.BasicFileAttributes;
38 import java.nio.file.attribute.BasicFileAttributeView;
39 import java.nio.file.attribute.FileAttribute;
40 import java.nio.file.attribute.FileTime;
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 import static java.nio.file.StandardOpenOption.*;
47 import static java.nio.file.StandardCopyOption.*;
153 end = offsets[endIndex];
154 }
155 return new JrtPath(jrtfs, path.substring(begin, end));
156 }
157
158 @Override
159 public final JrtPath toRealPath(LinkOption... options) throws IOException {
160 return jrtfs.toRealPath(this, options);
161 }
162
163 @Override
164 public final JrtPath toAbsolutePath() {
165 if (isAbsolute())
166 return this;
167 return new JrtPath(jrtfs, "/" + path, true);
168 }
169
170 @Override
171 public final URI toUri() {
172 try {
173 return new URI("jrt", toAbsolutePath().path, null);
174 } catch (URISyntaxException ex) {
175 throw new AssertionError(ex);
176 }
177 }
178
179 private boolean equalsNameAt(JrtPath other, int index) {
180 int mbegin = offsets[index];
181 int mlen;
182 if (index == (offsets.length - 1)) {
183 mlen = path.length() - mbegin;
184 } else {
185 mlen = offsets[index + 1] - mbegin - 1;
186 }
187 int obegin = other.offsets[index];
188 int olen;
189 if (index == (other.offsets.length - 1)) {
190 olen = other.path.length() - obegin;
191 } else {
192 olen = other.offsets[index + 1] - obegin - 1;
193 }
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
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 package jdk.internal.jrtfs;
26
27 import java.io.File;
28 import java.io.IOError;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.net.URI;
33 import java.net.URISyntaxException;
34 import java.nio.channels.FileChannel;
35 import java.nio.channels.SeekableByteChannel;
36 import java.nio.file.*;
37 import java.nio.file.DirectoryStream.Filter;
38 import java.nio.file.attribute.BasicFileAttributes;
39 import java.nio.file.attribute.BasicFileAttributeView;
40 import java.nio.file.attribute.FileAttribute;
41 import java.nio.file.attribute.FileTime;
42 import java.util.Iterator;
43 import java.util.Map;
44 import java.util.NoSuchElementException;
45 import java.util.Objects;
46 import java.util.Set;
47 import static java.nio.file.StandardOpenOption.*;
48 import static java.nio.file.StandardCopyOption.*;
154 end = offsets[endIndex];
155 }
156 return new JrtPath(jrtfs, path.substring(begin, end));
157 }
158
159 @Override
160 public final JrtPath toRealPath(LinkOption... options) throws IOException {
161 return jrtfs.toRealPath(this, options);
162 }
163
164 @Override
165 public final JrtPath toAbsolutePath() {
166 if (isAbsolute())
167 return this;
168 return new JrtPath(jrtfs, "/" + path, true);
169 }
170
171 @Override
172 public final URI toUri() {
173 try {
174 String p = toAbsolutePath().path;
175 if (!p.startsWith("/modules") || p.contains("..")) {
176 throw new IOError(new RuntimeException(p + " cannot be represented as URI"));
177 }
178
179 p = p.substring("/modules".length());
180 if (p.isEmpty()) {
181 p = "/";
182 }
183 return new URI("jrt", p, null);
184 } catch (URISyntaxException ex) {
185 throw new AssertionError(ex);
186 }
187 }
188
189 private boolean equalsNameAt(JrtPath other, int index) {
190 int mbegin = offsets[index];
191 int mlen;
192 if (index == (offsets.length - 1)) {
193 mlen = path.length() - mbegin;
194 } else {
195 mlen = offsets[index + 1] - mbegin - 1;
196 }
197 int obegin = other.offsets[index];
198 int olen;
199 if (index == (other.offsets.length - 1)) {
200 olen = other.path.length() - obegin;
201 } else {
202 olen = other.offsets[index + 1] - obegin - 1;
203 }
|