/** * Reads all bytes from the given input stream, closes it * and returns the result in an array.<p> * * @param in the input stream to read the bytes from * @return the byte content of the input stream * * @throws IOException in case of errors in the underlying java.io methods used */ public static byte[] readFully(InputStream in) throws IOException { return readFully(in, true); }
/** * Reads the specified number of bytes from the given input stream and returns the result in an array.<p> * * @param in the input stream to read the bytes from * @param size the number of bytes to read * * @return the byte content read from the input stream * * @throws IOException in case of errors in the underlying java.io methods used */ public static byte[] readFully(InputStream in, int size) throws IOException { return readFully(in, size, true); }
/** * Reads all bytes from the given input stream, closes it * and returns the result in an array.<p> * * @param in the input stream to read the bytes from * @return the byte content of the input stream * * @throws IOException in case of errors in the underlying java.io methods used */ public static byte[] readFully(InputStream in) throws IOException { return readFully(in, true); }
/** * Reads the specified number of bytes from the given input stream and returns the result in an array.<p> * * @param in the input stream to read the bytes from * @param size the number of bytes to read * * @return the byte content read from the input stream * * @throws IOException in case of errors in the underlying java.io methods used */ public static byte[] readFully(InputStream in, int size) throws IOException { return readFully(in, size, true); }
/** * Reads a file from the RFS and returns the file content.<p> * * @param file the file to read * @return the read file content * * @throws IOException in case of file access errors */ public static byte[] readFile(File file) throws IOException { // create input and output stream FileInputStream in = new FileInputStream(file); // read the content return readFully(in, (int)file.length()); }
/** * Reads a file from the RFS and returns the file content.<p> * * @param file the file to read * @return the read file content * * @throws IOException in case of file access errors */ @SuppressWarnings("resource") public static byte[] readFile(File file) throws IOException { // create input and output stream FileInputStream in = new FileInputStream(file); // read the content return readFully(in, (int)file.length()); }
/** * Creates a copy of the original input stream, which allows to read the input stream more then * once, required for certain document types.<p> * * @param in the inpur stram to copy * @return a copy of the original input stream * @throws IOException in case of read errors from the original input stream */ public InputStream getStreamCopy(InputStream in) throws IOException { if (m_inputBuffer != null) { return new ByteArrayInputStream(m_inputBuffer); } // read the input stream fully and copy it to a byte array m_inputBuffer = CmsFileUtil.readFully(in); // now return a reader from the byte array return new ByteArrayInputStream(m_inputBuffer); }
/** * Reads a file with the given name from the class loader and returns the file content.<p> * * @param filename the file to read * @return the read file content * * @throws IOException in case of file access errors */ @SuppressWarnings("resource") public static byte[] readFile(String filename) throws IOException { // create input and output stream InputStream in = CmsFileUtil.class.getClassLoader().getResourceAsStream(filename); if (in == null) { throw new FileNotFoundException(filename); } return readFully(in); }
/** * Reads a file with the given name from the class loader and returns the file content.<p> * * @param filename the file to read * @return the read file content * * @throws IOException in case of file access errors */ public static byte[] readFile(String filename) throws IOException { // create input and output stream InputStream in = CmsFileUtil.class.getClassLoader().getResourceAsStream(filename); if (in == null) { throw new FileNotFoundException(filename); } return readFully(in); }
/** * @see org.opencms.search.extractors.I_CmsTextExtractor#extractText(java.io.InputStream, java.lang.String) */ public I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception { // read the byte content byte[] text = CmsFileUtil.readFully(in); // call byte array based method of extraction return extractText(text, encoding); }
/** * @see org.opencms.search.extractors.I_CmsTextExtractor#extractText(java.io.InputStream, java.lang.String) */ public I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception { // read the byte content byte[] text = CmsFileUtil.readFully(in); // call byte array based method of extraction return extractText(text, encoding); }
return readFully(in, in.available(), closeInputStream);
/** * Reads the content of an input stream into a string (using UTF-8 encoding), performs a function on the string, and returns the result * again as an input stream.<p> * * @param stream the stream producing the input data * @param transformation the function to apply to the input * * @return the stream producing the transformed input data */ public static InputStream filterUtf8ResourceStream(InputStream stream, Function<String, String> transformation) { try { byte[] streamData = CmsFileUtil.readFully(stream); String dataAsString = new String(streamData, "UTF-8"); byte[] transformedData = transformation.apply(dataAsString).getBytes("UTF-8"); return new ByteArrayInputStream(transformedData); } catch (UnsupportedEncodingException e) { LOG.error(e.getLocalizedMessage(), e); return null; } catch (IOException e) { LOG.error(e.getLocalizedMessage(), e); throw new RuntimeException(e); } }
return readFully(in, in.available(), closeInputStream);
byte[] designBytes = CmsFileUtil.readFully(designStream, true); final String encoding = "UTF-8"; String design = new String(designBytes, encoding);
InputStream stream = getZipFile().getInputStream(entry); int size = new Long(entry.getSize()).intValue(); return CmsFileUtil.readFully(stream, size); } else {
byte[] pageBytes; pageBytes = CmsFileUtil.readFully( Thread.currentThread().getContextClassLoader().getResourceAsStream( "org/opencms/ui/login/login-fragment.html"));
setErrorAttributes(cms, throwable, request); byte[] pageBytes = CmsFileUtil.readFully( Thread.currentThread().getContextClassLoader().getResourceAsStream( "org/opencms/ui/error/error-page.html"));
byte[] content = CmsFileUtil.readFully(inputStream);
byte[] newContent = CmsFileUtil.readFully(contentInput); file.setContents(newContent); boolean wasLocked = ensureLock(cms, resource);