@SuppressWarnings("unchecked") private DocumentFile<T> getDocumentFile(HttpRequest request) throws ParseException, IOException, JsonException { HttpEntity requestEntity = ((HttpEntityEnclosingRequest) request).getEntity(); String requestContent = EntityUtils.toString(requestEntity, "UTF-8"); Object o = SerializationUtils.fromJson(requestContent); if(!(o instanceof Map)) { return null; } Map<String, Object> map = (Map<String, Object>) o; DocumentID<T> id = io.toDocumentId(map.get("documentId")); String fileName = (String) map.get("fileName"); Date d = (Date) map.get("uploadDate"); String encoding = (String) map.get("encoding"); String mimetype = (String) map.get("mimetype"); String savedByStage = (String) map.get("savedByStage"); InputStream is; if(encoding == null) { is = new ByteArrayInputStream(Base64.decodeBase64(((String)map.get("stream")).getBytes("UTF-8"))); } else { is = new ByteArrayInputStream(Base64.decodeBase64(((String)map.get("stream")).getBytes(encoding))); } DocumentFile<T> df = new DocumentFile<T>(id, fileName, is, savedByStage, d); df.setEncoding(encoding); df.setMimetype(mimetype); return df; }
DocumentFile<Local> df = new DocumentFile<Local>(docid, fileName, is, savedByStage, d); df.setEncoding(encoding); df.setMimetype(mimetype);
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()); }
public void postDocuments(int numberToPost) throws JsonException, IOException, HttpException, URISyntaxException { RemotePipeline rp = new HttpRemotePipeline("insertStage"); for(int i=0; i<numberToPost; i++) { rp.saveFull(LocalDocumentFactory.getRandomStringDocument("in", "id")); RemotePipeline rp2 = new HttpRemotePipeline("fileAdder"); LocalDocument ld = rp2.getDocument(new LocalQuery()); File f = getFile(); FileInputStream fis = new FileInputStream(f); DocumentFile<Local> df = new DocumentFile<Local>(ld.getID(), f.getName(), fis); df.setEncoding(new InputStreamReader(df.getStream()).getEncoding()); df.setMimetype("application/msword"); rp2.saveFile(df); } }
private DocumentFile<MongoType> getDocumentFile(DocumentID<MongoType> id, String filename) { DBObject query = QueryBuilder.start(DOCUMENT_KEY).is(id.getID()).and(FILENAME_KEY).is(filename).get(); GridFSDBFile file = documentfs.findOne(query); if(file==null) { return null; } DocumentFile<MongoType> df = new DocumentFile<MongoType>(id, file.getFilename(), file.getInputStream(), (String)file.get(STAGE_KEY), file.getUploadDate()); if(file.containsField(MIMETYPE_KEY)) { df.setMimetype((String) file.get(MIMETYPE_KEY)); } if(file.containsField(ENCODING_KEY)) { df.setEncoding((String) file.get(ENCODING_KEY)); } return df; }