/*
 * Minio Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 Minio, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.minio;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Object stat information.
 */
@SuppressWarnings("unused")
public class ObjectStat {
  private final String bucketName;
  private final String name;
  private final Date createdTime;
  private final long length;
  private final String etag;
  private final String contentType;
  // Encryption Key available in the object header
  private final String contentKey;
  // Encryption IV available in the object header
  private final String encryptionIv;
  // Encryption material description available in the object header
  private final String matDesc;
  private final Map<String,List<String>> httpHeaders;

  /**
   * Creates ObjectStat with given bucket name, object name, and available response header information.
   */
  public ObjectStat(String bucketName, String name, ResponseHeader header, Map<String,List<String>> httpHeaders) {
    this.bucketName = bucketName;
    this.name = name;
    this.contentType = header.contentType();
    this.createdTime = (Date) header.lastModified().clone();
    this.length = header.contentLength();

    if (header.etag() != null) {
      this.etag = header.etag().replaceAll("\"", "");
    } else {
      this.etag = "";
    }

    // set encryption related values
    this.contentKey = header.xamzMetaKey();
    this.encryptionIv = header.xamzMetaIv();
    this.matDesc = header.xamzMetaMatdesc();

    this.httpHeaders = httpHeaders;
  }


  /**
   * Creates ObjectStat with given bucket name, object name, created time, object length, Etag and content type.
   */
  public ObjectStat(String bucketName, String name, Date createdTime, long length, String etag, String contentType) {
    this.bucketName = bucketName;
    this.name = name;
    this.contentType = contentType;
    this.createdTime = (Date) createdTime.clone();
    this.length = length;
    if (etag != null) {
      this.etag = etag.replaceAll("\"", "");
    } else {
      this.etag = "";
    }
    this.contentKey = null;
    this.encryptionIv = null;
    this.matDesc = null;
    this.httpHeaders = null;
  }


  /**
   * Checks whether given object is same as this ObjectStat.
   */
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    ObjectStat that = (ObjectStat) o;

    if (length != that.length) {
      return false;
    }
    if (!bucketName.equals(that.bucketName)) {
      return false;
    }
    if (!name.equals(that.name)) {
      return false;
    }
    if (!createdTime.equals(that.createdTime)) {
      return false;
    }
    if (!etag.equals(that.etag)) {
      return false;
    }
    return contentType.equals(that.contentType);

  }


  /**
   * Returns hash of this ObjectStat.
   */
  @Override
  public int hashCode() {
    int result = bucketName.hashCode();
    result = 31 * result + name.hashCode();
    result = 31 * result + createdTime.hashCode();
    result = 31 * result + (int) (length ^ (length >>> 32));
    result = 31 * result + etag.hashCode();
    result = 31 * result + contentType.hashCode();
    return result;
  }


  /**
   * Returns bucket name.
   */
  public String bucketName() {
    return bucketName;
  }

  /**
   * Returns object name.
   */
  public String name() {
    return name;
  }


  /**
   * Returns created time.
   */
  public Date createdTime() {
    return (Date) createdTime.clone();
  }


  /**
   * Returns object length.
   */
  public long length() {
    return length;
  }

  /**
   * Returns ETag.
   */
  public String etag() {
    return etag;
  }

  /**
   * Returns content type of object.
   */
  public String contentType() {
    return contentType;
  }

  /**
   * Returns ObjectStat as string.
   */
  @Override
  public String toString() {
    return "ObjectStat{"
        + "bucket='"
        + bucketName
        + '\''
        + ", name='"
        + name + '\''
        + ", contentType='"
        + contentType
        + '\''
        + ", createdTime="
        + createdTime
        + ", length="
        + length
        + ", etag='"
        + etag
        + '\''
        + '}';
  }

  /**
   * Returns encryption key.
   */
  public String contentKey() {
    return contentKey;
  }

  /**
   * Returns encryption IV.
   */
  public String encryptionIv() {
    return encryptionIv;
  }

  /**
   * Returns encryption material description.
   */
  public String matDesc() {
    return matDesc;
  }

  /**
   * Gets HTTP headers.
   */
  public Map<String,List<String>> httpHeaders() {
    return httpHeaders;
  }
}

@@ -1444,32 +1444,288 @@
 ormation.%0A   */%0A
+  public ObjectStat(String bucketName, String name, ResponseHeader header) %7B%0A    this(bucketName, name, header, null);%0A  %7D%0A%0A%0A  /**%0A   * Creates ObjectStat with given bucket name, object name, available response header and HTTP Headers from response.%0A   */%0A
   public ObjectS

make ObjectStat backward compatible (#626)