/** * Returns the file's content. */ public FileContent getContent() throws FileSystemException { synchronized (fs) { attach(); if (content == null) { content = new DefaultFileContent(this, getFileContentInfoFactory()); } return content; } }
/** * Writes this content to an OutputStream. * * @param output The target OutputStream. * @param bufferSize The buffer size to write data chunks. * @return the total number of bytes written * @throws IOException if an error occurs writing the file. * @since 2.1 */ @Override public long write(final OutputStream output, final int bufferSize) throws IOException { final InputStream input = this.getInputStream(); long count = 0; try { // This read/write code from Apache Commons IO final byte[] buffer = new byte[bufferSize]; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } } finally { input.close(); } return count; } }
/** * Returns an output stream for writing the content. * * @return The OutputStream for the file. * @throws FileSystemException if an error occurs. */ @Override public OutputStream getOutputStream() throws FileSystemException { return getOutputStream(false); }
/** * Returns an input stream for reading the content. * * @return The InputStream * @throws FileSystemException if an error occurs. */ @Override public InputStream getInputStream() throws FileSystemException { /* * if (getThreadData().getState() == STATE_WRITING || getThreadData().getState() == STATE_RANDOM_ACCESS) { throw * new FileSystemException("vfs.provider/read-in-use.error", file); } */ // Get the raw input stream final InputStream inputStream = fileObject.getInputStream(); final InputStream wrappedInputStream = new FileContentInputStream(fileObject, inputStream); getOrCreateThreadData().addInstr(wrappedInputStream); streamOpened(); return wrappedInputStream; }
/** * Writes this content to an OutputStream. * * @param output The target OutputStream. * @return the total number of bytes written * @throws IOException if an error occurs writing the content. * @since 2.1 */ @Override public long write(final OutputStream output) throws IOException { return write(output, WRITE_BUFFER_SIZE); }
/** * Handles the end of input stream. */ private void endInput(final FileContentInputStream instr) { final FileContentThreadData fileContentThreadData = threadLocal.get(); if (fileContentThreadData != null) { fileContentThreadData.removeInstr(instr); } if (fileContentThreadData == null || !fileContentThreadData.hasStreams()) { // remove even when no value is set to remove key threadLocal.remove(); } streamClosed(); }
FileSystemException caught = null; try { final FileContentThreadData fileContentThreadData = getOrCreateThreadData();
/** * Gets the value of an attribute. * * @param attrName The attribute name. * @return The value of the attribute or null. * @throws FileSystemException if an error occurs. */ @Override public Object getAttribute(final String attrName) throws FileSystemException { getAttributes(); return attrs.get(attrName); }
((DefaultFileContent) this.file.getContent()).resetAttributes();
/** * Returns an input stream for reading the content. * * @return The InputStream * @throws FileSystemException if an error occurs. */ @Override public InputStream getInputStream() throws FileSystemException { /* * if (getThreadData().getState() == STATE_WRITING || getThreadData().getState() == STATE_RANDOM_ACCESS) { throw * new FileSystemException("vfs.provider/read-in-use.error", file); } */ // Get the raw input stream final InputStream inputStream = fileObject.getInputStream(); final InputStream wrappedInputStream = new FileContentInputStream(fileObject, inputStream); getOrCreateThreadData().addInstr(wrappedInputStream); streamOpened(); return wrappedInputStream; }
/** * Writes this content to an OutputStream. * * @param output The target OutputStream. * @return the total number of bytes written * @throws IOException if an error occurs writing the content. * @since 2.1 */ @Override public long write(final OutputStream output) throws IOException { return write(output, WRITE_BUFFER_SIZE); }
/** * Handles the end of random access. */ private void endRandomAccess(final RandomAccessContent rac) { final FileContentThreadData fileContentThreadData = threadLocal.get(); if (fileContentThreadData != null) { fileContentThreadData.removeRastr(rac); } if (fileContentThreadData == null || !fileContentThreadData.hasStreams()) { // remove even when no value is set to remove key threadLocal.remove(); } streamClosed(); }
FileSystemException caught = null; try { final FileContentThreadData fileContentThreadData = getOrCreateThreadData();
/** * Gets the value of an attribute. * * @param attrName The attribute name. * @return The value of the attribute or null. * @throws FileSystemException if an error occurs. */ @Override public Object getAttribute(final String attrName) throws FileSystemException { getAttributes(); return attrs.get(attrName); }
((DefaultFileContent) this.file.getContent()).resetAttributes();
/** * Returns an input/output stream to use to read and write the content of the file in an random manner. * * @param mode The RandomAccessMode. * @return A RandomAccessContent object to access the file. * @throws FileSystemException if an error occurs. */ @Override public RandomAccessContent getRandomAccessContent(final RandomAccessMode mode) throws FileSystemException { /* * if (getThreadData().getState() != STATE_NONE) { throw new * FileSystemException("vfs.provider/read-in-use.error", file); } */ // Get the content final RandomAccessContent rastr = fileObject.getRandomAccessContent(mode); final FileRandomAccessContent rac = new FileRandomAccessContent(fileObject, rastr); getOrCreateThreadData().addRastr(rac); streamOpened(); return rac; }
/** * Writes this content to an OutputStream. * * @param output The target OutputStream. * @return the total number of bytes written * @throws IOException if an error occurs writing the content. * @since 2.1 */ @Override public long write(final OutputStream output) throws IOException { return write(output, WRITE_BUFFER_SIZE); }
/** * Handles the end of random access. */ private void endRandomAccess(final RandomAccessContent rac) { final FileContentThreadData fileContentThreadData = threadLocal.get(); if (fileContentThreadData != null) { fileContentThreadData.removeRastr(rac); } if (fileContentThreadData == null || !fileContentThreadData.hasStreams()) { // remove even when no value is set to remove key threadLocal.remove(); } streamClosed(); }
/** * Create a FileContent implementation. * * @return The FileContent. * @throws FileSystemException if an error occurs. * @since 2.0 */ protected FileContent doCreateFileContent() throws FileSystemException { return new DefaultFileContent(this, getFileContentInfoFactory()); }
/** * Returns an output stream for writing the content. * * @return The OutputStream for the file. * @throws FileSystemException if an error occurs. */ @Override public OutputStream getOutputStream() throws FileSystemException { return getOutputStream(false); }