public boolean saveFile(DocumentFile df) throws IOException { HttpResponse response = core.post(getFileUrl(df), SerializationUtils.toJson(df)); int code = response.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK || code == HttpStatus.SC_NO_CONTENT) { EntityUtils.consume(response.getEntity()); return true; } else { logUnexpected(response); return false; } }
private String getFileUrl(String fileName, Object docid) throws UnsupportedEncodingException { return fileUrl + "&" + RemotePipeline.FILENAME_PARAM + "=" + fileName + "&" + RemotePipeline.DOCID_PARAM + "=" + URLEncoder.encode(SerializationUtils.toJson(docid), "UTF-8"); }
@SuppressWarnings("unchecked") public List<String> getFileNames(Object docid) throws IOException { HttpResponse response = core.get( fileUrl + "&" + RemotePipeline.DOCID_PARAM + "=" + URLEncoder.encode(SerializationUtils.toJson(docid), "UTF-8")); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { try { return (List<String>) SerializationUtils.toObject(EntityUtils.toString(response.getEntity())); } catch (JsonException e) { throw new IOException(e); } } else { logUnexpected(response); return null; } }
public DocumentFile getFile(String fileName, Object docid) throws IOException { HttpResponse response = core.get(getFileUrl(fileName, docid)); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Object o; try { o = SerializationUtils.toObject(EntityUtils.toString(response.getEntity())); } catch (JsonException e) { throw new IOException(e); } if (!(o instanceof Map)) { return null; } @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) o; Date d = new Date((Long) 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 df = new DocumentFile(docid, fileName, is, savedByStage, d); df.setEncoding(encoding); df.setMimetype(mimetype); return df; } else { logUnexpected(response); return null; } }
public Map<String, Object> getProperties() throws IOException { HttpResponse response = core.get(propertyUrl); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Map<String, Object> map; try { map = SerializationUtils.fromJson(EntityUtils.toString(response.getEntity())); } catch (JsonException e) { throw new IOException(e); } InternalLogger.debug("Successfully retrieved propertyMap with " + map.size() + " entries"); return map; } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { InternalLogger.debug("No document found matching query"); EntityUtils.consume(response.getEntity()); return null; } else { logUnexpected(response); return null; } }