コード例 #1
0
ファイル: MassiveClient.java プロジェクト: antelder/tool.lars
  public Attachment addAttachment(final String assetId, final AttachmentSummary attSummary)
      throws IOException, BadVersionException, RequestFailureException {
    final Attachment attach = attSummary.getAttachment();
    final String name = attSummary.getName();
    // Info about the attachment goes into the URL
    String urlString = "/assets/" + assetId + "/attachments?name=" + name;
    if (attach.getType() != null) {
      urlString = urlString + "&type=" + attach.getType().toString();
    }

    HttpURLConnection connection = createHttpURLConnectionToMassive(urlString);
    if (attSummary.getURL() == null) {
      writeMultiPart(assetId, attSummary, connection);
    } else {
      writeSinglePart(assetId, attSummary, connection);
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    testResponseCode(connection);
    InputStream is = connection.getInputStream();
    int len = 0;
    while ((len = is.read()) != -1) {
      baos.write((byte) len);
    }
    is.close();
    baos.close();

    Attachment attachment =
        JSONAssetConverter.readValue(
            new ByteArrayInputStream(baos.toByteArray()), Attachment.class);

    return attachment;
  }
コード例 #2
0
ファイル: MassiveClient.java プロジェクト: antelder/tool.lars
 /**
  * Gets a single asset
  *
  * @param assetId The ID of the asset to obtain
  * @return The Asset
  * @throws IOException
  * @throws RequestFailureException
  */
 public Asset getAsset(String assetId)
     throws IOException, BadVersionException, RequestFailureException {
   HttpURLConnection connection = createHttpURLConnectionToMassive("/assets/" + assetId);
   connection.setRequestMethod("GET");
   testResponseCode(connection);
   return JSONAssetConverter.readValue(connection.getInputStream());
 }
コード例 #3
0
ファイル: MassiveClient.java プロジェクト: antelder/tool.lars
  /**
   * Adds an asset into Massive. Note that Massive will set some fields (such as ID) so it is
   * important to switch to the returned object after calling this method.
   *
   * @param asset The asset to add, it will not be modified by this method
   * @return The asset with information added by Massive
   * @throws IOException
   */
  public Asset addAsset(Asset asset)
      throws IOException, BadVersionException, RequestFailureException {

    HttpURLConnection connection = createHttpURLConnectionToMassive("/assets");
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setDoOutput(true);
    JSONAssetConverter.writeValue(connection.getOutputStream(), asset);
    testResponseCode(connection);
    Asset returnedAsset = JSONAssetConverter.readValue(connection.getInputStream());
    returnedAsset = getAsset(returnedAsset.get_id());
    return returnedAsset;
  }