/** * @return Creates a temporary handler for temporary files. * @throws IOException */ public static FileSystemAttachmentPersistenceHandler newTemporaryHandler() throws IOException { return new FileSystemAttachmentPersistenceHandler(createTemporaryFolder()); }
/** * Gets the persistence handler that will be used to store the uploaded file. * * @return an instance of {@link IAttachmentPersistenceHandler} to store the uploaded file. */ private IAttachmentPersistenceHandler<? extends IAttachmentRef> getAttachmentPersistenceTemporaryHandler() { return new InMemoryAttachmentPersistenceHandler(); }
private FileSystemAttachmentRef newRef(String id, String hash, String filePath, long length, String name) { return new FileSystemAttachmentRef(id, hash, filePath, length, name); }
@Override public FileSystemAttachmentRef addAttachment(File file, long length, String name, String hashSha1) { FileSystemAttachmentRef ref = super.addAttachment(file, length, name, hashSha1); attachments.put(ref.getId(), ref); return ref; }
@Override public AttachmentCopyContext<FileSystemAttachmentRef> copy(IAttachmentRef attachmentRef, SDocument document) { AttachmentCopyContext<FileSystemAttachmentRef> acr = super.copy(attachmentRef, document); attachments.put(acr.getNewAttachmentRef().getId(), acr.getNewAttachmentRef()); return acr; }
@Override public FileSystemAttachmentRef getAttachment(String fileId) { if(fileId != null){ File file = findFileFromId(fileId); if (file.exists()) { return toRef(file); } } return null; }
@Override public void deleteAttachment(String key, SDocument document) { if (key != null) { TempFileUtils.deleteOrException(findFileFromId(key), getClass()); TempFileUtils.deleteOrException(infoFileFromId(key), getClass()); } } }
@Override public FileSystemAttachmentRef addAttachment(File file, long length, String name, String hashSha1) { try (FileInputStream fis = new FileInputStream(file)){ return addAttachment(fis, length, name, hashSha1); } catch (Exception e) { throw new SingularFormException("Erro lendo origem de dados", e); } }
@Override public void deleteAttachment(String key, SDocument document) { super.deleteAttachment(key, document); attachments.remove(key); }
@Override protected File findFileFromId(String fileId) { File f = super.findFileFromId(fileId); f.deleteOnExit(); return f; }
@Override protected File infoFileFromId(String fileId) { File f = super.infoFileFromId(fileId); f.deleteOnExit(); return f; } }
private FileSystemAttachmentRef newRef(String id, String hash, String filePath, long length, String name) { return new FileSystemAttachmentRef(id, hash, filePath, length, name); }
/** * @return Creates a temporary handler for temporary files. * @throws IOException */ public static FileSystemAttachmentPersistenceHandler newTemporaryHandler() throws IOException { return new FileSystemAttachmentPersistenceHandler(createTemporaryFolder()); }
@Override public FileSystemAttachmentRef addAttachment(File file, long length, String name) { FileSystemAttachmentRef ref = super.addAttachment(file, length, name); attachments.put(ref.getId(), ref); return ref; }
@Override public AttachmentCopyContext<FileSystemAttachmentRef> copy(IAttachmentRef attachmentRef, SDocument document) { AttachmentCopyContext<FileSystemAttachmentRef> acr = super.copy(attachmentRef, document); attachments.put(acr.getNewAttachmentRef().getId(), acr.getNewAttachmentRef()); return acr; }
@Override public FileSystemAttachmentRef getAttachment(String fileId) { if(fileId != null){ File file = findFileFromId(fileId); if (file.exists()) { return toRef(file); } } return null; }
@Override public void deleteAttachment(String key, SDocument document) { if (key != null) { TempFileUtils.deleteOrException(findFileFromId(key), getClass()); TempFileUtils.deleteOrException(infoFileFromId(key), getClass()); } } }
@Override public FileSystemAttachmentRef addAttachment(File file, long length, String name) { try (FileInputStream fis = new FileInputStream(file)){ return addAttachment(fis, length, name); } catch (Exception e) { throw new SingularFormException("Erro lendo origem de dados", e); } }
@Override public void deleteAttachment(String key, SDocument document) { super.deleteAttachment(key, document); attachments.remove(key); }
@Override public AttachmentCopyContext<FileSystemAttachmentRef> copy(IAttachmentRef attachmentRef, SDocument document) { try (InputStream is = attachmentRef.getContentAsInputStream()){ return new AttachmentCopyContext<>(addAttachment(is, attachmentRef.getSize(), attachmentRef.getName(), attachmentRef.getHashSHA1())); } catch (Exception e) { throw SingularException.rethrow(e); } }