@Override public void write(OutputStream output) throws IOException, WebApplicationException { if (uniqueId != null && fileName != null && indexName != null) { InputStream is = indexManager.getAssociatedDocumentStream(indexName, uniqueId, fileName); if (is != null) { StreamHelper.copyStream(is, output); } else { throw new WebApplicationException("Cannot find associated document with uniqueId <" + uniqueId + "> with fileName <" + fileName + ">", LumongoConstants.NOT_FOUND); } } else { throw new WebApplicationException(LumongoConstants.ID + " and " + LumongoConstants.FILE_NAME + " are required", LumongoConstants.BAD_REQUEST); } }
public void storeAssociated(String uniqueId, String indexName, String fileName, Map<String, String> meta, InputStream source, Boolean compressed) throws IOException { HttpURLConnection conn = null; OutputStream destination = null; try { HashMap<String, Object> parameters = new HashMap<>(); parameters.put(LumongoConstants.ID, uniqueId); parameters.put(LumongoConstants.FILE_NAME, fileName); parameters.put(LumongoConstants.INDEX, indexName); if (meta != null) { ArrayList<Object> list = new ArrayList<>(); parameters.put(LumongoConstants.META, list); for (String key : meta.keySet()) { String value = meta.get(key); list.add(key + ":" + value); } } if (compressed != null) { parameters.put(LumongoConstants.COMPRESSED, compressed.toString()); } String url = HttpHelper.createRequestUrl(server, restPort, LumongoConstants.ASSOCIATED_DOCUMENTS_URL, parameters); conn = createPostConnection(url); destination = conn.getOutputStream(); StreamHelper.copyStream(source, destination); handlePossibleError(conn); } finally { closeStreams(source, destination, conn); } }
public void fetchAssociated(String uniqueId, String indexName, String fileName, OutputStream destination) throws IOException { InputStream source = null; HttpURLConnection conn = null; try { HashMap<String, Object> parameters = new HashMap<>(); parameters.put(LumongoConstants.ID, uniqueId); parameters.put(LumongoConstants.FILE_NAME, fileName); parameters.put(LumongoConstants.INDEX, indexName); String url = HttpHelper.createRequestUrl(server, restPort, LumongoConstants.ASSOCIATED_DOCUMENTS_URL, parameters); conn = createGetConnection(url); handlePossibleError(conn); source = conn.getInputStream(); StreamHelper.copyStream(source, destination); } finally { closeStreams(source, destination, conn); } }