doThrow(new ContentIOException()).when(StubbedObject).putContent(contentStream);
public void contentStreamClosed() throws ContentIOException { try { channel.close(); } catch (IOException e) { throw new ContentIOException("Failed to close underlying channel", e); } } };
public void contentStreamClosed() throws ContentIOException { try { channel.close(); } catch (IOException e) { throw new ContentIOException("Failed to close underlying channel", e); } } };
public Void execute() throws Throwable { try { connector.appendContent(info, contentStream, isLastChunk); } catch(IOException e) { throw new ContentIOException("", e); } return null; } }, false, true);
public Void execute() throws Throwable { try { connector.appendContent(info, contentStream, isLastChunk); } catch(IOException e) { throw new ContentIOException("", e); } return null; } }, false, true);
/** * Private: for Spring-constructed instances only. * * @param rootDirectory * the root under which files will be stored. The directory will be created if it does not exist. */ private FileContentStore(File rootDirectory) { if (!rootDirectory.exists()) { if (!rootDirectory.mkdirs()) { throw new ContentIOException("Failed to create store root: " + rootDirectory, null); } } this.rootDirectory = rootDirectory.getAbsoluteFile(); rootAbsolutePath = rootDirectory.getAbsolutePath(); allowRandomAccess = true; readOnly = false; }
/** * Private: for Spring-constructed instances only. * * @param rootDirectory * the root under which files will be stored. The directory will be created if it does not exist. */ private FileContentStore(File rootDirectory) { if (!rootDirectory.exists()) { if (!rootDirectory.mkdirs()) { throw new ContentIOException("Failed to create store root: " + rootDirectory, null); } } this.rootDirectory = rootDirectory.getAbsoluteFile(); rootAbsolutePath = rootDirectory.getAbsolutePath(); allowRandomAccess = true; readOnly = false; }
private void ensureFileInContentStore(File file) { String fileNormalizedAbsoultePath = FilenameUtils.normalize(file.getAbsolutePath()); String rootNormalizedAbsolutePath = FilenameUtils.normalize(rootAbsolutePath); if (!fileNormalizedAbsoultePath.startsWith(rootNormalizedAbsolutePath)) { throw new ContentIOException("Access to files outside of content store root is not allowed: " + file); } } }
private void ensureFileInContentStore(File file) { String fileNormalizedAbsoultePath = FilenameUtils.normalize(file.getAbsolutePath()); String rootNormalizedAbsolutePath = FilenameUtils.normalize(rootAbsolutePath); if (!fileNormalizedAbsoultePath.startsWith(rootNormalizedAbsolutePath)) { throw new ContentIOException("Access to files outside of content store root is not allowed: " + file); } } }
/** * Populates a file with the content in the reader, but also converts the encoding to UTF-8. */ private void saveContentInUtf8File(ContentReader reader, File file) { String encoding = reader.getEncoding(); try { Reader in = new InputStreamReader(reader.getContentInputStream(), encoding); Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), "UTF-8"); FileCopyUtils.copy(in, out); // both streams are closed } catch (IOException e) { throw new ContentIOException("Failed to copy content to file and convert "+encoding+" to UTF-8: \n" + " file: " + file, e); } } }
@Override protected ReadableByteChannel getDirectReadableChannel() throws ContentIOException { try { // Interpret the URL to generate the text InputStream textStream = textGenerator.getInputStream(seed, size, words); ReadableByteChannel textChannel = Channels.newChannel(textStream); // done if (logger.isDebugEnabled()) { logger.debug("Opened read channel to random text for URL: " + getContentUrl()); } return textChannel; } catch (Throwable e) { throw new ContentIOException("Failed to read channel: " + this, e); } }
public final void putContent(File file) throws ContentIOException { try { OutputStream os = getContentOutputStream(); FileInputStream is = new FileInputStream(file); copyStreams(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content from file: \n" + " writer: " + this + "\n" + " file: " + file, e); } }
public final void putContent(File file) throws ContentIOException { try { OutputStream os = getContentOutputStream(); FileInputStream is = new FileInputStream(file); copyStreams(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content from file: \n" + " writer: " + this + "\n" + " file: " + file, e); } }
public final void getContent(File file) throws ContentIOException { try { InputStream is = getContentInputStream(); FileOutputStream os = new FileOutputStream(file); FileCopyUtils.copy(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content to file: \n" + " accessor: " + this + "\n" + " file: " + file, e); } }
public final void getContent(File file) throws ContentIOException { try { InputStream is = getContentInputStream(); FileOutputStream os = new FileOutputStream(file); FileCopyUtils.copy(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content to file: \n" + " accessor: " + this + "\n" + " file: " + file, e); } }
public final void putContent(InputStream is) throws ContentIOException { try { OutputStream os = getContentOutputStream(); copyStreams(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content from input stream: \n" + " writer: " + this, e); } }
/** * @see Channels#newOutputStream(java.nio.channels.WritableByteChannel) */ public OutputStream getContentOutputStream() throws ContentIOException { try { WritableByteChannel channel = getWritableChannel(); OutputStream is = new BufferedOutputStream(Channels.newOutputStream(channel)); // done return is; } catch (Throwable e) { throw new ContentIOException("Failed to open stream onto channel: \n" + " writer: " + this, e); } }
public final void putContent(InputStream is) throws ContentIOException { try { OutputStream os = getContentOutputStream(); copyStreams(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content from input stream: \n" + " writer: " + this, e); } }
/** * Copies the {@link #getContentInputStream() input stream} to the given * <code>OutputStream</code> */ public final void getContent(OutputStream os) throws ContentIOException { try { InputStream is = getContentInputStream(); FileCopyUtils.copy(is, os); // both streams are closed // done } catch (IOException e) { throw new ContentIOException("Failed to copy content to output stream: \n" + " accessor: " + this, e); } }
protected void checkUser() throws ContentIOException { String username = AuthenticationUtil.getFullyAuthenticatedUser(); if (!expectedUsername.equals(username)) { throw new ContentIOException( "Expected username '" + expectedUsername + "' but found '" + username + "'"); } }