@Override public boolean deleteDocumentFile(DatabaseDocument<MemoryType> d, String fileName) { for (DocumentFile<MemoryType> f : files) { if (f.getDocumentId().equals(d.getID()) && f.getFileName().equals(fileName)) { files.remove(f); return true; } } return false; }
@Override public List<String> getDocumentFileNames(DatabaseDocument<MemoryType> d) { ArrayList<String> list = new ArrayList<String>(); for (DocumentFile<MemoryType> f : files) { if (f.getDocumentId().equals(d.getID())) { list.add(f.getFileName()); } } return list; }
private String getFileUrl(DocumentFile<Local> df) throws UnsupportedEncodingException { return getFileUrl(df.getFileName(), df.getDocumentId()); }
@Override public DocumentFile<MemoryType> getDocumentFile( DatabaseDocument<MemoryType> d, String fileName) { for (DocumentFile<MemoryType> f : files) { if (f.getDocumentId().getID().equals(d.getID().getID()) && f.getFileName().equals(fileName)) { try { return copy(f); } catch (IOException e) { logger.error("Error copying the streams", e); } } } return null; }
private boolean writeAttachments(DatabaseDocument<MemoryType> d, List<DocumentFile<MemoryType>> attachments) { for(DocumentFile<MemoryType> attachment: attachments) { attachment.setDocumentId(d.getID()); try { write(attachment); } catch (IOException e) { logger.error( String.format( "Exception while writing filename:%s for id:%s", attachment.getFileName(), d.getID() ), e ); return false; } } return true; }
private boolean writeAttachments(DatabaseDocument<MongoType> d, List<DocumentFile<MongoType>> attachments) { for(DocumentFile<MongoType> attachment: attachments) { attachment.setDocumentId(d.getID()); try { write(attachment); } catch (IOException e) { logger.error( String.format( "Exception while writing filename:%s for id:%s", attachment.getFileName(), d.getID() ), e ); return false; } } return true; }
private DocumentFile<MemoryType> copy(DocumentFile<MemoryType> df) throws IOException { String s = IOUtils.toString(df.getStream(), df.getEncoding()); df.getStream().close(); df.setStream(IOUtils.toInputStream(s, df.getEncoding())); return new DocumentFile<MemoryType>(df.getDocumentId(), df.getFileName(), IOUtils.toInputStream(s, df.getEncoding()), df.getSavedByStage(), df.getUploadDate()); }
.is(df.getDocumentId().getID()) .and(FILENAME_KEY) .is(df.getFileName()); documentfs.remove(qb.get()); GridFSInputFile input = documentfs.createFile(df.getStream(), df.getFileName()); input.put(DOCUMENT_KEY, df.getDocumentId().getID()); input.put(ENCODING_KEY, df.getEncoding());