/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read( InputStream stream ) throws IOException { return IoUtil.read(stream); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Binary#getBytes() */ public byte[] getBytes() { try { return IoUtil.readBytes(file); } catch (IOException e) { throw new IoException(e); } }
/** * 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); }
private InputStream getInputStreamForFile( String cndFileString ) { return IoUtil.getResourceAsStream(cndFileString, repository.environment().getClassLoader(this), null); }
return this.getString().equals(that.getString()); case PropertyType.BINARY: return IoUtil.isSame(this.getStream(), that.getBinary().getStream()); case PropertyType.BOOLEAN: return this.getBoolean() == that.getBoolean();
private InputStream getInputStreamForFile( String cndFileString ) { return IoUtil.getResourceAsStream(cndFileString, repository.environment().getClassLoader(this), null); }
return this.getString().equals(that.getString()); case PropertyType.BINARY: return IoUtil.isSame(this.getStream(), that.getBinary().getStream()); case PropertyType.BOOLEAN: return this.getBoolean() == that.getBoolean();
/** * Read and return the entire contents of the supplied {@link Reader}. This method always closes the reader when finished * reading. * * @param reader the reader of the contents; may be null * @return the contents, or an empty string if the supplied reader is null * @throws IOException if there is an error reading the content */ public static String read( Reader reader ) throws IOException { return IoUtil.read(reader); }
public InMemoryTestBinary( InputStream is ) throws IOException { this(IoUtil.readBytes(is)); }
/** * 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); }
private InputStream getInitialContentFileStream( String workspaceName ) { String initialContentFileString = initialContentConfig.getInitialContentFile(workspaceName); InputStream stream = IoUtil.getResourceAsStream(initialContentFileString, repository.environment().getClassLoader(this), null); if (stream == null) { repository.warn(JcrI18n.cannotLoadInitialContentFile, initialContentFileString); } return stream; }
/** * Read and return the entire contents of the supplied {@link Reader}. This method always closes the reader when finished * reading. * * @param reader the reader of the contents; may be null * @return the contents, or an empty string if the supplied reader is null * @throws IOException if there is an error reading the content */ public static String read( Reader reader ) throws IOException { return IoUtil.read(reader); }
/** * Read and return the entire contents of the supplied {@link File file}. * * @param file the file containing the contents; may be null * @return the contents, or an empty byte array if the supplied file is null * @throws IOException if there is an error reading the content */ public static byte[] readBytes( File file ) throws IOException { if (file == null) return new byte[] {}; InputStream stream = new BufferedInputStream(new FileInputStream(file)); boolean error = false; try { return readBytes(stream); } catch (IOException e) { error = true; // this error should be thrown, even if there is an error closing stream throw e; } catch (RuntimeException e) { error = true; // this error should be thrown, even if there is an error closing stream throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } }
/** * 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); }
private InputStream getInitialContentFileStream( String workspaceName ) { String initialContentFileString = initialContentConfig.getInitialContentFile(workspaceName); InputStream stream = IoUtil.getResourceAsStream(initialContentFileString, repository.environment().getClassLoader(this), null); if (stream == null) { repository.warn(JcrI18n.cannotLoadInitialContentFile, initialContentFileString); } return stream; }
/** * Read and return the entire contents of the supplied {@link Reader}. This method always closes the reader when finished * reading. * * @param reader the reader of the contents; may be null * @return the contents, or an empty string if the supplied reader is null * @throws IOException if there is an error reading the content */ public static String read( Reader reader ) throws IOException { return IoUtil.read(reader); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.BinaryFactory#create(java.io.File) */ public Binary create( File file ) throws ValueFormatException, IoException { if (file == null) return null; if (!file.canRead()) return null; if (!file.isFile()) return null; try { byte[] value = IoUtil.readBytes(file); return create(value); } catch (IOException err) { throw new IoException(GraphI18n.errorConvertingIo.text(file, Binary.class.getSimpleName()), err); } }
/** * 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); }
/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read( InputStream stream ) throws IOException { return IoUtil.read(stream); }
/** * {@inheritDoc} */ public Binary create( InputStream stream, long approximateLength ) throws IoException { if (stream == null) return null; try { byte[] value = IoUtil.readBytes(stream); return create(value); } catch (IOException err) { throw new IoException(GraphI18n.errorConvertingIo.text(InputStream.class.getSimpleName(), Binary.class.getSimpleName()), err); } }