/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param input the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( InputStream input, OutputStream stream ) throws IOException { write(input, stream, 1024); }
/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param content the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( String content, OutputStream stream ) throws IOException { IoUtil.write(content, stream); }
/** * Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when * finished. * * @param content the content to write to the writer; may be null * @param writer the writer to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the writer is null */ public static void write( String content, Writer writer ) throws IOException { IoUtil.write(content, writer); }
/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param input the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( InputStream input, OutputStream stream ) throws IOException { write(input, stream, 1024); }
/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param content the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( String content, OutputStream stream ) throws IOException { IoUtil.write(content, stream); }
/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param content the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( String content, OutputStream stream ) throws IOException { IoUtil.write(content, stream); }
/** * Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when * finished. * * @param content the content to write to the writer; may be null * @param writer the writer to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the writer is null */ public static void write( String content, Writer writer ) throws IOException { IoUtil.write(content, writer); }
/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param input the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( InputStream input, OutputStream stream ) throws IOException { write(input, stream, 1024); }
/** * Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when * finished. * * @param content the content to write to the writer; may be null * @param writer the writer to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the writer is null */ public static void write( String content, Writer writer ) throws IOException { IoUtil.write(content, writer); }
private static void createFile( File parent, String path ) throws Exception { File file = new File(parent, path); IoUtil.write(new ByteArrayInputStream("some content".getBytes()), new FileOutputStream(file)); } }
/** * Converts input stream into ByteBuffer. * * @param stream * @return the byte buffer * @throws IOException */ private ByteBuffer buffer( InputStream stream ) throws IOException { stream.reset(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); IoUtil.write(stream, bout); return ByteBuffer.wrap(bout.toByteArray()); }
/** * Converts input stream into ByteBuffer. * * @param stream * @return the byte buffer * @throws IOException */ private ByteBuffer buffer( InputStream stream ) throws IOException { stream.reset(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); IoUtil.write(stream, bout); return ByteBuffer.wrap(bout.toByteArray()); }
private void writeProperties( File propertiesFile, Map<String, Object> properties ) throws IOException { StringBuilder content = new StringBuilder(); for (Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); content.append(entry.getKey()).append("=").append(valueToString(entry.getValue())); if (it.hasNext()) { content.append(";"); } } IoUtil.write(content.toString(), propertiesFile); }
private void storeStringAtKey( String string, BinaryKey key) throws BinaryStoreException { File tmpFile = null; try { tmpFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX + EXTRACTED_TEXT_SUFFIX); IoUtil.write(string, new BufferedOutputStream(new FileOutputStream(tmpFile))); saveTempFileToStore(tmpFile, key, tmpFile.length()); } catch (IOException e) { throw new BinaryStoreException(e); } finally { if (tmpFile != null) { tmpFile.delete(); } } }
protected static void addFile( File directory, String path, String contentFile ) throws IOException { File file = new File(directory, path); IoUtil.write(FileSystemConnectorTest.class.getClassLoader().getResourceAsStream(contentFile), new FileOutputStream(file)); }
private void addFile( String path, String contentFile ) throws IOException { File file = new File(directory, path); IoUtil.write(getClass().getClassLoader().getResourceAsStream(contentFile), new FileOutputStream(file)); } }
public void initialize() throws IOException { if (directory.exists()) FileUtil.delete(directory); directory.mkdirs(); // Make some content ... new File(directory, "dir1").mkdir(); new File(directory, "dir2").mkdir(); new File(directory, "dir3").mkdir(); File simpleJson = new File(directory, "dir3/simple.json"); IoUtil.write(getClass().getClassLoader().getResourceAsStream("data/simple.json"), new FileOutputStream(simpleJson)); File simpleTxt = new File(directory, "dir3/simple.txt"); IoUtil.write(TEXT_CONTENT, new FileOutputStream(simpleTxt)); }
private void prepareExternalDirectory( String dirpath ) throws IOException { FileUtil.delete(dirpath); new File(dirpath).mkdir(); File file = new File(dirpath + "/file.txt"); IoUtil.write(JcrRepositoryStartupTest.class.getClassLoader().getResourceAsStream("io/file1.txt"), new FileOutputStream(file)); }
@Before public void before() throws Exception { FileUtil.delete("target/files"); File fileConnectorTestDir = new File("target/files"); fileConnectorTestDir.mkdir(); File testFile = new File(fileConnectorTestDir, "testFile"); IoUtil.write(getClass().getClassLoader().getResourceAsStream("data/simple.json"), new FileOutputStream(testFile)); }
private void readLargeBinary() throws Exception { Node commit = session.getNode("/repos/git-modeshape-remote/tree/master/modeshape-jcr/src/test/resources/docs/postgresql-8.4.1-US.pdf"); assertNotNull(commit); Binary data = commit.getNode("jcr:content").getProperty("jcr:data").getBinary(); long size = data.getSize(); assertTrue(size > 0); //simply read the stream to make sure it's valid ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); IoUtil.write(data.getStream(), bos); assertEquals("invalid binary stream", size, baos.toByteArray().length); }