1 // Copyright 2009 Google Inc. All rights reserved.
3 package com
.google
.appengine
.api
.blobstore
;
5 import java
.io
.IOException
;
6 import java
.io
.ObjectInputStream
;
7 import java
.io
.Serializable
;
11 * {@code BlobInfo} contains metadata about a blob. This metadata is gathered by
12 * parsing the HTTP headers included in the blob upload.
14 * @see <a href="http://tools.ietf.org/html/rfc1867">RFC 1867</a> for
15 * the specification of HTTP file uploads.
17 public class BlobInfo
implements Serializable
{
18 private static final long serialVersionUID
= 4530115855912621409L;
19 private static final String DEFAULT_MD5_HASH
= "";
20 protected final BlobKey blobKey
;
21 protected final String contentType
;
22 protected final Date creation
;
23 protected final String filename
;
24 protected final long size
;
25 protected String md5Hash
;
28 * Creates a {@code BlobInfo} by providing the {@link BlobKey} and all
29 * associated metadata. This is typically done by the API on the developer's
32 * @param blobKey the {@link BlobKey} of the Blob.
33 * @param contentType the MIME Content-Type provided in the HTTP header during upload of this
35 * @param creation the time and date the blob was uploaded.
36 * @param filename the file included in the Content-Disposition HTTP header during upload of
38 * @param size the size in bytes of this Blob.
39 * @param md5Hash the md5Hash of this Blob.
41 public BlobInfo(BlobKey blobKey
, String contentType
, Date creation
, String filename
,
42 long size
, String md5Hash
) {
43 if (blobKey
== null) {
44 throw new NullPointerException("blobKey must not be null");
46 if (contentType
== null) {
47 throw new NullPointerException("contentType must not be null");
49 if (creation
== null) {
50 throw new NullPointerException("creation must not be null");
52 if (filename
== null) {
53 throw new NullPointerException("filename must not be null");
55 if (md5Hash
== null) {
56 throw new NullPointerException("md5Hash must not be null");
59 this.blobKey
= blobKey
;
60 this.contentType
= contentType
;
61 this.creation
= creation
;
62 this.filename
= filename
;
64 this.md5Hash
= md5Hash
;
67 public BlobInfo(BlobKey blobKey
, String contentType
, Date creation
, String filename
, long size
) {
68 this(blobKey
, contentType
, creation
, filename
, size
, DEFAULT_MD5_HASH
);
72 * Returns the {@link BlobKey} of the Blob this {@code BlobInfo} describes.
74 public BlobKey
getBlobKey() {
79 * Returns the MIME Content-Type provided in the HTTP header during upload of
82 public String
getContentType() {
87 * Returns the time and date the blob was upload.
89 public Date
getCreation() {
94 * Returns the file included in the Content-Disposition HTTP header during
95 * upload of this Blob.
97 public String
getFilename() {
102 * Returns the size in bytes of this Blob.
104 public long getSize() {
109 * Returns the md5Hash of this Blob.
111 public String
getMd5Hash() {
116 public boolean equals(Object obj
) {
117 if (obj
instanceof BlobInfo
) {
118 BlobInfo bi
= (BlobInfo
) obj
;
119 return blobKey
.equals(bi
.blobKey
) &&
120 contentType
.equals(bi
.contentType
)
122 creation
.equals(bi
.creation
) &&
123 filename
.equals(bi
.filename
) &&
125 md5Hash
.equals(bi
.md5Hash
);
131 public int hashCode() {
133 hash
= hash
* 37 + blobKey
.hashCode();
134 hash
= hash
* 37 + contentType
.hashCode();
135 hash
= hash
* 37 + filename
.hashCode();
136 hash
= hash
* 37 + md5Hash
.hashCode();
141 public String
toString() {
142 StringBuilder builder
= new StringBuilder();
143 builder
.append("<BlobInfo: ");
144 builder
.append(blobKey
);
145 builder
.append(", contentType = ");
146 builder
.append(contentType
);
147 builder
.append(", creation = ");
148 builder
.append(creation
.toString());
149 builder
.append(", filename = ");
150 builder
.append(filename
);
151 builder
.append(", size = ");
152 builder
.append(Long
.toString(size
));
153 builder
.append(", md5Hash = ");
154 builder
.append(md5Hash
);
156 return builder
.toString();
159 private void readObject(ObjectInputStream in
)
160 throws IOException
, ClassNotFoundException
{
161 in
.defaultReadObject();
162 if (md5Hash
== null) {
163 md5Hash
= DEFAULT_MD5_HASH
;