215 } 216 String syntax = syntaxAndInput.substring(0, pos); 217 String input = syntaxAndInput.substring(pos + 1); 218 String expr; 219 if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) { 220 expr = JrtUtils.toRegexPattern(input); 221 } else { 222 if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) { 223 expr = input; 224 } else { 225 throw new UnsupportedOperationException("Syntax '" + syntax 226 + "' not recognized"); 227 } 228 } 229 // return matcher 230 final Pattern pattern = Pattern.compile(expr); 231 return (Path path) -> pattern.matcher(path.toString()).matches(); 232 } 233 234 // These methods throw read only file system exception 235 final void setTimes(byte[] path, FileTime mtime, FileTime atime, FileTime ctime) 236 throws IOException { 237 throw readOnly(); 238 } 239 240 final void createDirectory(byte[] path, FileAttribute<?>... attrs) throws IOException { 241 throw readOnly(); 242 } 243 244 final void deleteFile(byte[] path, boolean failIfNotExists) 245 throws IOException { 246 throw readOnly(); 247 } 248 249 final OutputStream newOutputStream(byte[] path, OpenOption... options) 250 throws IOException { 251 throw readOnly(); 252 } 253 254 final void copyFile(boolean deletesrc, byte[] src, byte[] dst, CopyOption... options) 255 throws IOException { 256 throw readOnly(); 257 } 258 259 final FileChannel newFileChannel(byte[] path, 260 Set<? extends OpenOption> options, 261 FileAttribute<?>... attrs) 262 throws IOException { 263 throw new UnsupportedOperationException("newFileChannel"); 264 } 265 266 final InputStream newInputStream(byte[] path) throws IOException { 267 return new ByteArrayInputStream(getFileContent(path)); 268 } 269 270 final SeekableByteChannel newByteChannel(byte[] path, 271 Set<? extends OpenOption> options, 272 FileAttribute<?>... attrs) 273 throws IOException { 274 checkOptions(options); 275 276 byte[] buf = getFileContent(path); 277 final ReadableByteChannel rbc 278 = Channels.newChannel(new ByteArrayInputStream(buf)); 279 final long size = buf.length; 280 return new SeekableByteChannel() { 281 long read = 0; 282 283 @Override 284 public boolean isOpen() { 285 return rbc.isOpen(); 286 } 287 288 @Override 289 public long position() throws IOException { 290 return read; 291 } 292 293 @Override 294 public SeekableByteChannel position(long pos) 295 throws IOException { 296 throw new UnsupportedOperationException(); 311 throw new NonWritableChannelException(); 312 } 313 314 @Override 315 public int write(ByteBuffer src) throws IOException { 316 throw new NonWritableChannelException(); 317 } 318 319 @Override 320 public long size() throws IOException { 321 return size; 322 } 323 324 @Override 325 public void close() throws IOException { 326 rbc.close(); 327 } 328 }; 329 } 330 331 final JrtFileStore getFileStore(AbstractJrtPath path) { 332 return new JrtFileStore(path); 333 } 334 335 final void ensureOpen() throws IOException { 336 if (!isOpen()) { 337 throw new ClosedFileSystemException(); 338 } 339 } 340 341 // abstract methods to be implemented by a particular jrt file system 342 abstract AbstractJrtPath getRootPath(); 343 344 abstract boolean isSameFile(AbstractJrtPath p1, AbstractJrtPath p2) throws IOException; 345 346 abstract boolean isLink(AbstractJrtPath jrtPath) throws IOException; 347 348 abstract AbstractJrtPath resolveLink(AbstractJrtPath jrtPath) throws IOException; 349 350 abstract AbstractJrtFileAttributes getFileAttributes(byte[] path, LinkOption... options) throws IOException; 351 352 abstract boolean exists(byte[] path) throws IOException; 353 354 abstract boolean isDirectory(byte[] path, boolean resolveLinks) throws IOException; 355 356 /** 357 * returns the list of child paths of the given directory "path" 358 * 359 * @param path name of the directory whose content is listed 360 * @param childPrefix prefix added to returned children names - may be null 361 * in which case absolute child paths are returned 362 * @return iterator for child paths of the given directory path 363 */ 364 abstract Iterator<Path> iteratorOf(byte[] path, String childPrefix) 365 throws IOException; 366 367 // returns the content of the file resource specified by the path 368 abstract byte[] getFileContent(byte[] path) throws IOException; 369 } | 215 } 216 String syntax = syntaxAndInput.substring(0, pos); 217 String input = syntaxAndInput.substring(pos + 1); 218 String expr; 219 if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) { 220 expr = JrtUtils.toRegexPattern(input); 221 } else { 222 if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) { 223 expr = input; 224 } else { 225 throw new UnsupportedOperationException("Syntax '" + syntax 226 + "' not recognized"); 227 } 228 } 229 // return matcher 230 final Pattern pattern = Pattern.compile(expr); 231 return (Path path) -> pattern.matcher(path.toString()).matches(); 232 } 233 234 // These methods throw read only file system exception 235 final void setTimes(AbstractJrtPath jrtPath, FileTime mtime, FileTime atime, FileTime ctime) 236 throws IOException { 237 throw readOnly(); 238 } 239 240 final void createDirectory(AbstractJrtPath jrtPath, FileAttribute<?>... attrs) throws IOException { 241 throw readOnly(); 242 } 243 244 final void deleteFile(AbstractJrtPath jrtPath, boolean failIfNotExists) 245 throws IOException { 246 throw readOnly(); 247 } 248 249 final OutputStream newOutputStream(AbstractJrtPath jrtPath, OpenOption... options) 250 throws IOException { 251 throw readOnly(); 252 } 253 254 final void copyFile(boolean deletesrc, AbstractJrtPath srcPath, AbstractJrtPath dstPath, CopyOption... options) 255 throws IOException { 256 throw readOnly(); 257 } 258 259 final FileChannel newFileChannel(AbstractJrtPath jrtPath, 260 Set<? extends OpenOption> options, 261 FileAttribute<?>... attrs) 262 throws IOException { 263 throw new UnsupportedOperationException("newFileChannel"); 264 } 265 266 final InputStream newInputStream(AbstractJrtPath jrtPath) throws IOException { 267 return new ByteArrayInputStream(getFileContent(jrtPath)); 268 } 269 270 final SeekableByteChannel newByteChannel(AbstractJrtPath jrtPath, 271 Set<? extends OpenOption> options, 272 FileAttribute<?>... attrs) 273 throws IOException { 274 checkOptions(options); 275 276 byte[] buf = getFileContent(jrtPath); 277 final ReadableByteChannel rbc 278 = Channels.newChannel(new ByteArrayInputStream(buf)); 279 final long size = buf.length; 280 return new SeekableByteChannel() { 281 long read = 0; 282 283 @Override 284 public boolean isOpen() { 285 return rbc.isOpen(); 286 } 287 288 @Override 289 public long position() throws IOException { 290 return read; 291 } 292 293 @Override 294 public SeekableByteChannel position(long pos) 295 throws IOException { 296 throw new UnsupportedOperationException(); 311 throw new NonWritableChannelException(); 312 } 313 314 @Override 315 public int write(ByteBuffer src) throws IOException { 316 throw new NonWritableChannelException(); 317 } 318 319 @Override 320 public long size() throws IOException { 321 return size; 322 } 323 324 @Override 325 public void close() throws IOException { 326 rbc.close(); 327 } 328 }; 329 } 330 331 final JrtFileStore getFileStore(AbstractJrtPath jrtPath) { 332 return new JrtFileStore(jrtPath); 333 } 334 335 final void ensureOpen() throws IOException { 336 if (!isOpen()) { 337 throw new ClosedFileSystemException(); 338 } 339 } 340 341 // abstract methods to be implemented by a particular jrt file system 342 abstract AbstractJrtPath getRootPath(); 343 344 abstract boolean isSameFile(AbstractJrtPath jrtPath1, AbstractJrtPath jrtPath2) throws IOException; 345 346 abstract boolean isLink(AbstractJrtPath jrtPath) throws IOException; 347 348 abstract AbstractJrtPath resolveLink(AbstractJrtPath jrtPath) throws IOException; 349 350 abstract AbstractJrtFileAttributes getFileAttributes(AbstractJrtPath jrtPath, LinkOption... options) throws IOException; 351 352 abstract boolean exists(AbstractJrtPath jrtPath) throws IOException; 353 354 abstract boolean isDirectory(AbstractJrtPath jrtPath, boolean resolveLinks) throws IOException; 355 356 /** 357 * returns the list of child paths of the given directory "path" 358 * 359 * @param path name of the directory whose content is listed 360 * @return iterator for child paths of the given directory path 361 */ 362 abstract Iterator<Path> iteratorOf(AbstractJrtPath jrtPath) throws IOException; 363 364 // returns the content of the file resource specified by the path 365 abstract byte[] getFileContent(AbstractJrtPath jrtPath) throws IOException; 366 } |