@Override public InputStream openInputStream() throws IOException { if (!exists()) { throw new ResourceException.NotFound(absolutePath()); } if (isDirectory()) { throw new ResourceException.FileIsDirectory(absolutePath()); } return new FileInputStream(file); }
@Override public InputStream openInputStream() throws IOException { if (!exists()) { throw new ResourceException.NotFound(absolutePath()); } if (isDirectory()) { throw new ResourceException.FileIsDirectory(absolutePath()); } return new FileInputStream(file); }
throw new ResourceException.NotFound(absolutePath()); } else if (!file.canWrite()) { throw new ResourceException.PermissionDenied(absolutePath()); throw new ResourceException.NotFound(absolutePath());
throw new ResourceException.NotFound(absolutePath()); } else if (!file.canWrite()) { throw new ResourceException.PermissionDenied(absolutePath()); throw new ResourceException.NotFound(absolutePath());
/** * @deprecated * * Opens a new input stream to read the contents of a resource and returns it. * Note that implementations may be allocating native memory for the stream, so * callers need to close this when they are done with it. users of this * method should follow the pattern: close the stream where you open it. * * @return just opened InputStream * @throws ResourceException is the file does not exists or if the resource is a directory */ default InputStream inputStream() throws ResourceException { if (!exists()) { throw new ResourceException.NotFound(absolutePath()); } if (isDirectory()) { throw new ResourceException.FileIsDirectory(absolutePath()); } try { return openInputStream(); } catch (IOException e) { throw new ResourceException.IOError(e); } }
/** * @deprecated * * Opens a new input stream to read the contents of a resource and returns it. * Note that implementations may be allocating native memory for the stream, so * callers need to close this when they are done with it. users of this * method should follow the pattern: close the stream where you open it. * * @return just opened InputStream * @throws ResourceException is the file does not exists or if the resource is a directory */ default InputStream inputStream() throws ResourceException { if (!exists()) { throw new ResourceException.NotFound(absolutePath()); } if (isDirectory()) { throw new ResourceException.FileIsDirectory(absolutePath()); } try { return openInputStream(); } catch (IOException e) { throw new ResourceException.IOError(e); } }
private void throwFromErrno(final int err) throws IOException { Errno errno = Errno.valueOf(err); switch (errno) { case EACCES: throw new ResourceException.PermissionDenied(absolutePath()); case EEXIST: throw new ResourceException.FileExists(absolutePath()); case EINVAL: throw new ResourceException.InvalidArguments(absolutePath()); case ENOENT: throw new ResourceException.NotFound(absolutePath()); case ELOOP: throw new ResourceException.TooManySymlinks(absolutePath()); case EISDIR: throw new ResourceException.FileIsDirectory(absolutePath()); case ENOTDIR: throw new ResourceException.FileIsNotDirectory(absolutePath()); case EMFILE: default: throw new InternalIOException(errno.description()); } }
private void throwFromErrno(final int err) throws IOException { Errno errno = Errno.valueOf(err); switch (errno) { case EACCES: throw new ResourceException.PermissionDenied(absolutePath()); case EEXIST: throw new ResourceException.FileExists(absolutePath()); case EINVAL: throw new ResourceException.InvalidArguments(absolutePath()); case ENOENT: throw new ResourceException.NotFound(absolutePath()); case ELOOP: throw new ResourceException.TooManySymlinks(absolutePath()); case EISDIR: throw new ResourceException.FileIsDirectory(absolutePath()); case ENOTDIR: throw new ResourceException.FileIsNotDirectory(absolutePath()); case EMFILE: default: throw new InternalIOException(errno.description()); } }
@Override public Channel openChannel(int flags, int perm) throws IOException { throw new ResourceException.NotFound(absolutePath()); }
@Override public InputStream openInputStream() throws IOException { throw new ResourceException.NotFound(""); }
@Override public InputStream openInputStream() throws IOException { throw new ResourceException.NotFound(""); }
static IOException mapFileNotFoundOnGetChannel(final FileResource file, final FileNotFoundException ex) { // Java throws FileNotFoundException both if the file doesn't exist or there were // permission issues, but Ruby needs to disambiguate those two cases return file.exists() ? new ResourceException.PermissionDenied(file.absolutePath()) : new ResourceException.NotFound(file.absolutePath()); }
@Override public Channel openChannel(int flags, int perm) throws IOException { throw new ResourceException.NotFound(absolutePath()); }
static IOException mapFileNotFoundOnGetChannel(final FileResource file, final FileNotFoundException ex) { // Java throws FileNotFoundException both if the file doesn't exist or there were // permission issues, but Ruby needs to disambiguate those two cases return file.exists() ? new ResourceException.PermissionDenied(file.absolutePath()) : new ResourceException.NotFound(file.absolutePath()); }