@Override public InputStream read() throws ResourceException { try { return _uri.toURL().openStream(); } catch (Exception e) { throw new ResourceException(this, "Failed to open InputStream", e); } }
@Override public InputStream read() throws ResourceException { try { return _uri.toURL().openStream(); } catch (Exception e) { throw new ResourceException(this, "Failed to open InputStream", e); } }
private OutputStream createOutputStream(boolean append) throws ResourceException { ByteArrayOutputStream out = new ByteArrayOutputStream() { @Override public void flush() throws IOException { super.flush(); _contents = toByteArray(); _lastModified = System.currentTimeMillis(); } }; if (append) { try { out.write(_contents); } catch (IOException e) { throw new ResourceException(this, e); } } return out; }
private OutputStream createOutputStream(boolean append) throws ResourceException { ByteArrayOutputStream out = new ByteArrayOutputStream() { @Override public void flush() throws IOException { super.flush(); _contents = toByteArray(); _lastModified = System.currentTimeMillis(); } }; if (append) { try { out.write(_contents); } catch (IOException e) { throw new ResourceException(this, e); } } return out; }
@Override public OutputStream write() throws ResourceException { if (_file.isDirectory()) { throw new ResourceException(this, "Cannot write to directory: " + _file); } return FileHelper.getOutputStream(_file); }
@Override public boolean isExists() { try { return _fileObject.exists(); } catch (FileSystemException e) { throw new ResourceException(this, e); } }
@Override public boolean isExists() { try { return _fileObject.exists(); } catch (final FileSystemException e) { throw new ResourceException(this, e); } }
@Override public boolean isReadOnly() { try { return !_fileObject.isWriteable(); } catch (FileSystemException e) { throw new ResourceException(this, e); } }
@Override public boolean isReadOnly() { try { return !_fileObject.isWriteable(); } catch (final FileSystemException e) { throw new ResourceException(this, e); } }
@Override public OutputStream write() throws ResourceException { if (_file.isDirectory()) { throw new ResourceException(this, "Cannot write to directory: " + _file); } return FileHelper.getOutputStream(_file); }
@Override public <E> E read(Function<InputStream, E> readCallback) throws ResourceException { final InputStream in = read(); try { final E result = readCallback.apply(in); return result; } catch (Exception e) { throw new ResourceException(this, "Error occurred in read callback", e); } finally { FileHelper.safeClose(in); } }
@Override public <E> E read(Function<InputStream, E> readCallback) throws ResourceException { final InputStream in = read(); try { final E result = readCallback.apply(in); return result; } catch (Exception e) { throw new ResourceException(this, "Error occurred in read callback", e); } finally { FileHelper.safeClose(in); } }
@Override public InputStream read() throws ResourceException { try { return _fileObject.getContent().getInputStream(); } catch (final FileSystemException e) { throw new ResourceException(this, e); } }
@Override public OutputStream append() throws ResourceException { try { final FileContent content = _fileObject.getContent(); return content.getOutputStream(true); } catch (final Exception e) { throw new ResourceException(this, e); } }
@Override public long getSize() { try { return _fileObject.getContent().getSize(); } catch (final FileSystemException e) { throw new ResourceException(this, e); } }
@Override public long getSize() { try { return _fileObject.getContent().getSize(); } catch (FileSystemException e) { throw new ResourceException(this, e); } }
@Override public OutputStream write() throws ResourceException { try { final FileContent content = _fileObject.getContent(); return content.getOutputStream(); } catch (final Exception e) { throw new ResourceException(this, e); } } }
@Override public InputStream read() throws ResourceException { try { return _fileObject.getContent().getInputStream(); } catch (FileSystemException e) { throw new ResourceException(this, e); } }
/** * Gets the underlying {@link RepositoryFile}. * * @return */ public RepositoryFile getRepositoryFile() throws ResourceException { if (_fileRef == null || _fileRef.get() == null) { throw new ResourceException(this, "RepositoryFile '" + _qualifiedPath + "' is not available since it was not serializable. The RepositoryFileResource instance can " + "be recreated using a live repository and the qualified path of the file."); } return _fileRef.get(); }
@Override public final void write(Action<OutputStream> writeCallback) throws ResourceException { final OutputStream out = write(); try { writeCallback.run(out); } catch (Exception e) { throw new ResourceException(this, "Error occurred in write callback", e); } finally { FileHelper.safeClose(out); } }