public static void write(HttpServletResponse response, File file) throws IOException { if (response instanceof BufferCacheServletResponse) { BufferCacheServletResponse bufferCacheServletResponse = (BufferCacheServletResponse)response; ByteBuffer byteBuffer = ByteBuffer.wrap(FileUtil.getBytes(file)); bufferCacheServletResponse.setByteBuffer(byteBuffer); } else { FileInputStream fileInputStream = new FileInputStream(file); try (FileChannel fileChannel = fileInputStream.getChannel()) { long contentLength = fileChannel.size(); setContentLength(response, contentLength); response.flushBuffer(); fileChannel.transferTo( 0, contentLength, Channels.newChannel(response.getOutputStream())); } } }
public byte[] getBytes() throws IOException { flush(); close(); return FileUtil.getBytes(_tempFile); }
/** * Returns the file as a byte array. * * @param companyId the primary key of the company * @param repositoryId the primary key of the data repository (optionally * {@link com.liferay.portal.kernel.model.CompanyConstants#SYSTEM}) * @param fileName the file's name * @return Returns the byte array with the file's name */ @Override public byte[] getFileAsBytes( long companyId, long repositoryId, String fileName) throws PortalException { try { InputStream is = getFileAsStream(companyId, repositoryId, fileName); return FileUtil.getBytes(is); } catch (IOException ioe) { throw new SystemException(ioe); } }
/** * Returns the file as a byte array. * * @param companyId the primary key of the company * @param repositoryId the primary key of the data repository (optionally * {@link com.liferay.portal.kernel.model.CompanyConstants#SYSTEM}) * @param fileName the file's name * @param versionLabel the file's version label * @return Returns the byte array with the file's name */ @Override public byte[] getFileAsBytes( long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException { try { InputStream is = getFileAsStream( companyId, repositoryId, fileName, versionLabel); return FileUtil.getBytes(is); } catch (IOException ioe) { throw new SystemException(ioe); } }
public byte[] getBytes() throws IOException { flush(); close(); return FileUtil.getBytes(_tempFile); }
protected byte[] getImageBytes( UploadRequest uploadRequest, String fieldNameValue) throws Exception { File file = uploadRequest.getFile(fieldNameValue + "File"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isNotEmpty(bytes)) { return bytes; } String url = uploadRequest.getParameter(fieldNameValue + "URL"); long imageId = GetterUtil.getLong( _http.getParameter(url, "img_id", false)); Image image = _imageLocalService.fetchImage(imageId); if (image == null) { return null; } return image.getTextObj(); }
FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId); logoBytes = FileUtil.getBytes(fileEntry.getContentStream());
smallImageBytes = FileUtil.getBytes(smallImageFile);
smallImageBytes = FileUtil.getBytes(smallImageFile);