Android Open Source - uppidy-android-sdk Api Body Part Resource






From Project

Back to project page uppidy-android-sdk.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...

If you think the Android project uppidy-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright (C) Uppidy Inc, 2012/*  w  w w .  ja va  2s .c  o m*/
 */
package com.uppidy.android.sdk.api;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.springframework.core.io.AbstractResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.util.Assert;

/**
 * @author arudnev@uppidy.com
 *
 */
public class ApiBodyPartResource extends AbstractResource {

  private final ApiBodyPart part;


  /**
   * Create a new ApiBodyPartResource.
   * <p>
   * @param part the part to get the stream from
   */
  public ApiBodyPartResource(ApiBodyPart part) {
    Assert.notNull(part, "part must not be null");
    this.part = part;
  }

  /**
   * Tries to open input stream.
   */
  @Override
  public boolean exists() {
    try {
      InputStream is = getInputStream();
      is.close();
      return true;
    }
    catch (Throwable isEx) {
      return false;
    }
  }

  public String getDescription() {
    return "part [" + this.part + "]";
  }

  public InputStream getInputStream() throws IOException {
    InputStreamSource source = part.getData();
    if (source == null) {
      throw new FileNotFoundException(getDescription() + " does not have input stream source");
    }
    InputStream inputStream = source.getInputStream();
    if (inputStream == null) {
      throw new FileNotFoundException(getDescription() + " cannot be opened because it does not exist");
    }
    return inputStream;
  }

  /**
   * This implementation compares the parts of the resources.
   */
  @Override
  public boolean equals(Object obj) {
    return (obj == this || (obj instanceof ApiBodyPartResource && this.part.equals(((ApiBodyPartResource) obj).part)));
  }

  /**
   * This implementation returns the hash code of the part.
   */
  @Override
  public int hashCode() {
    return this.part.hashCode();
  }

}




Java Source Code List

com.uppidy.android.sdk.api.ApiAppInfo.java
com.uppidy.android.sdk.api.ApiBodyPartResource.java
com.uppidy.android.sdk.api.ApiBodyPart.java
com.uppidy.android.sdk.api.ApiContactInfo.java
com.uppidy.android.sdk.api.ApiContact.java
com.uppidy.android.sdk.api.ApiContainer.java
com.uppidy.android.sdk.api.ApiConversation.java
com.uppidy.android.sdk.api.ApiEntity.java
com.uppidy.android.sdk.api.ApiLocation.java
com.uppidy.android.sdk.api.ApiMessage.java
com.uppidy.android.sdk.api.ApiModifications.java
com.uppidy.android.sdk.api.ApiObject.java
com.uppidy.android.sdk.api.ApiProfile.java
com.uppidy.android.sdk.api.ApiSync.java
com.uppidy.android.sdk.api.BackupOperations.java
com.uppidy.android.sdk.api.FeedOperations.java
com.uppidy.android.sdk.api.UppidyApi.java
com.uppidy.android.sdk.api.Uppidy.java
com.uppidy.android.sdk.api.UserOperations.java
com.uppidy.android.sdk.api.impl.AbstractUppidyOperations.java
com.uppidy.android.sdk.api.impl.BackupTemplate.java
com.uppidy.android.sdk.api.impl.FeedTemplate.java
com.uppidy.android.sdk.api.impl.UppidyErrorHandler.java
com.uppidy.android.sdk.api.impl.UppidyTemplate.java
com.uppidy.android.sdk.api.impl.UserTemplate.java
com.uppidy.android.sdk.backup.BackupService.java
com.uppidy.android.sdk.backup.MessageProvider.java
com.uppidy.android.sdk.backup.NetworkStateListener.java
com.uppidy.android.sdk.connect.UppidyAdapter.java
com.uppidy.android.sdk.connect.UppidyConnectionFactory.java
com.uppidy.android.sdk.connect.UppidyOAuth2Template.java
com.uppidy.android.sdk.connect.UppidyServiceProvider.java
com.uppidy.android.util.StringUtil.java