@Test public void testSave() throws Exception { MemoryDocument testDoc = new MemoryDocument(); mc.getDocumentWriter().insert(testDoc); RemotePipeline rp = new HttpRemotePipeline("localhost", server.getPort(), "stage"); String content = "adsafgoaiuhgahgo\ndasdas"; String fileName = "test.txt"; rp.saveFile(new DocumentFile<Local>(testDoc.getID().getLocalDocumentID(), fileName, IOUtils.toInputStream(content, "UTF-8"))); DocumentFile<MemoryType> df = mc.getDocumentReader().getDocumentFile(testDoc, fileName); if(df==null) { fail("File was not properly saved"); } if(!df.getFileName().equals(fileName)) { fail("File had wrong file name"); } String fc = IOUtils.toString(df.getStream(), "UTF-8"); if(!fc.equals(content)) { fail("File had wrong contents"); } }
@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; }
FileHandler implements ResponsibleHandler { @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; } }
FileHandler implements ResponsibleHandler { @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; } FileHandler(CachingDocumentNIO<T> io); }
FileHandler implements ResponsibleHandler { @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; } FileHandler(CachingDocumentNIO<T> io); @Override void handle(HttpRequest request, HttpResponse response, HttpContext context); @Override boolean supports(HttpRequest request); @Override String[] getSupportedUrls(); }
FileHandler implements ResponsibleHandler { @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; } FileHandler(CachingDocumentNIO<T> io); @Override void handle(HttpRequest request, HttpResponse response, HttpContext context); @Override boolean supports(HttpRequest request); @Override String[] getSupportedUrls();  }