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 public BlobInfo(BlobKey blobKey
, String contentType
, Date creation
, String filename
,
33 long size
, String md5Hash
) {
34 if (blobKey
== null) {
35 throw new NullPointerException("blobKey must not be null");
37 if (contentType
== null) {
38 throw new NullPointerException("contentType must not be null");
40 if (creation
== null) {
41 throw new NullPointerException("creation must not be null");
43 if (filename
== null) {
44 throw new NullPointerException("filename must not be null");
46 if (md5Hash
== null) {
47 throw new NullPointerException("md5Hash must not be null");
50 this.blobKey
= blobKey
;
51 this.contentType
= contentType
;
52 this.creation
= creation
;
53 this.filename
= filename
;
55 this.md5Hash
= md5Hash
;
58 public BlobInfo(BlobKey blobKey
, String contentType
, Date creation
, String filename
, long size
) {
59 this(blobKey
, contentType
, creation
, filename
, size
, DEFAULT_MD5_HASH
);
63 * Returns the {@link BlobKey} of the Blob this {@code BlobInfo} describes.
65 public BlobKey
getBlobKey() {
70 * Returns the MIME Content-Type provided in the HTTP header during upload of
73 public String
getContentType() {
78 * Returns the time and date the blob was upload.
80 public Date
getCreation() {
85 * Returns the file included in the Content-Disposition HTTP header during
86 * upload of this Blob.
88 public String
getFilename() {
93 * Returns the size in bytes of this Blob.
95 public long getSize() {
100 * Returns the md5Hash of this Blob.
102 public String
getMd5Hash() {
107 public boolean equals(Object obj
) {
108 if (obj
instanceof BlobInfo
) {
109 BlobInfo bi
= (BlobInfo
) obj
;
110 return blobKey
.equals(bi
.blobKey
) &&
111 contentType
.equals(bi
.contentType
)
113 creation
.equals(bi
.creation
) &&
114 filename
.equals(bi
.filename
) &&
116 md5Hash
.equals(bi
.md5Hash
);
122 public int hashCode() {
124 hash
= hash
* 37 + blobKey
.hashCode();
125 hash
= hash
* 37 + contentType
.hashCode();
126 hash
= hash
* 37 + filename
.hashCode();
127 hash
= hash
* 37 + md5Hash
.hashCode();
132 public String
toString() {
133 StringBuilder builder
= new StringBuilder();
134 builder
.append("<BlobInfo: ");
135 builder
.append(blobKey
);
136 builder
.append(", contentType = ");
137 builder
.append(contentType
);
138 builder
.append(", creation = ");
139 builder
.append(creation
.toString());
140 builder
.append(", filename = ");
141 builder
.append(filename
);
142 builder
.append(", size = ");
143 builder
.append(Long
.toString(size
));
144 builder
.append(", md5Hash = ");
145 builder
.append(md5Hash
);
147 return builder
.toString();
150 private void readObject(ObjectInputStream in
)
151 throws IOException
, ClassNotFoundException
{
152 in
.defaultReadObject();
153 if (md5Hash
== null) {
154 md5Hash
= DEFAULT_MD5_HASH
;