@Override public void scan(InputStream inputStream) throws AntivirusScannerException { File file = null; try { file = FileUtil.createTempFile(_ANTIVIRUS_EXTENSION); FileUtil.write(file, inputStream); scan(file); } catch (IOException ioe) { throw new SystemException("Unable to write temporary file", ioe); } finally { if (file != null) { file.delete(); } } }
@Override public void close() throws IOException { super.close(); _randomAccessFileCache.close(); FileUtil.delete(_file); }
@Override public void addFile( String name, InputStream is, String fileExt, int maxStringLength) { addText(name, FileUtil.extractText(is, fileExt, maxStringLength)); }
public static void write( File file, byte[] bytes, int offset, int length, boolean append) throws IOException { getFile().write(file, bytes, offset, length, append); }
@Override public ManifestSummary getManifestSummary( long userId, long groupId, Map<String, String[]> parameterMap, FileEntry fileEntry) throws Exception { File file = FileUtil.createTempFile("lar"); ZipReader zipReader = null; ManifestSummary manifestSummary = null; try (InputStream inputStream = _dlFileEntryLocalService.getFileAsStream( fileEntry.getFileEntryId(), fileEntry.getVersion(), false)) { FileUtil.write(file, inputStream); Group group = _groupLocalService.getGroup(groupId); String userIdStrategy = MapUtil.getString( parameterMap, PortletDataHandlerKeys.USER_ID_STRATEGY); zipReader = ZipReaderFactoryUtil.getZipReader(file); PortletDataContext portletDataContext = _portletDataContextFactory.createImportPortletDataContext( group.getCompanyId(), groupId, parameterMap, getUserIdStrategy(userId, userIdStrategy), zipReader); manifestSummary = getManifestSummary(portletDataContext); } finally { if (zipReader != null) { zipReader.close(); } FileUtil.delete(file); } return manifestSummary; }
public static void write( String pathName, String fileName, String s, boolean lazy) throws IOException { getFile().write(pathName, fileName, s, lazy); }
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())); } } }
file = FileUtil.createTempFile(bytes); FileUtil.delete(file);
public RandomAccessInputStream(InputStream inputStream) throws IOException { _inputStream = inputStream; _file = FileUtil.createTempFile(); _randomAccessFileCache = new RandomAccessFile(_file, "rw"); }
public static void write(File file, byte[] bytes) throws IOException { write(file, bytes, false); }
private static String _getUniqueFileName( long groupId, String fileName, long folderId) throws PortalException { fileName = FileUtil.stripParentheticalSuffix(fileName); FileEntry fileEntry = _fetchPortletFileEntry( groupId, fileName, folderId); if (fileEntry == null) { return fileName; } int suffix = 1; for (int i = 0; i < _UNIQUE_FILE_NAME_TRIES; i++) { String curFileName = FileUtil.appendParentheticalSuffix( fileName, String.valueOf(suffix)); fileEntry = _fetchPortletFileEntry(groupId, curFileName, folderId); if (fileEntry == null) { return curFileName; } suffix++; } throw new PortalException( StringBundler.concat( "Unable to get a unique file name for ", fileName, " in folder ", folderId)); }
protected String getUniqueFileName( ThemeDisplay themeDisplay, String fileName, long folderId) throws PortalException { FileEntry fileEntry = fetchFileEntry( themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), folderId, fileName); if (fileEntry == null) { return fileName; } int suffix = 1; for (int i = 0; i < _UNIQUE_FILE_NAME_TRIES; i++) { String curFileName = FileUtil.appendParentheticalSuffix( fileName, String.valueOf(suffix)); fileEntry = fetchFileEntry( themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), folderId, curFileName); if (fileEntry == null) { return curFileName; } suffix++; } throw new PortalException( "Unable to get a unique file name for " + fileName); }
file = FileUtil.createTempFile("lar"); FileUtil.write(file, attachmentsFileEntry.getContentStream()); FileUtil.delete(file);
public static void copyDirectory( String sourceDirName, String destinationDirName) throws IOException { getFile().copyDirectory(sourceDirName, destinationDirName); }
public byte[] getBytes() throws IOException { flush(); close(); return FileUtil.getBytes(_tempFile); }
smallImageFile = FileUtil.createTempFile(smallImageBytes);
file = FileUtil.createTempFile("lar"); FileUtil.write(file, attachmentsFileEntry.getContentStream()); FileUtil.delete(file);
public static void write( String fileName, String s, boolean lazy, boolean append) throws IOException { getFile().write(fileName, s, lazy, append); }
@Override public void scan(byte[] bytes) throws AntivirusScannerException { File file = null; try { file = FileUtil.createTempFile(_ANTIVIRUS_EXTENSION); FileUtil.write(file, bytes); scan(file); } catch (IOException ioe) { throw new SystemException("Unable to write temporary file", ioe); } finally { if (file != null) { file.delete(); } } }
/** * 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); } }