Exemple #1
0
  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;
    }
  }
Exemple #2
0
  @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;
    }
  }