Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / blobstore / FileInfo.java
blob8e7873dd8d6dcf05744570d763561b3d14fabc8c
1 package com.google.appengine.api.blobstore;
3 import java.util.Date;
5 /**
6 * {@code FileInfo} contains metadata about an uploaded file. This metadata is
7 * gathered by parsing the HTTP headers included in the file upload.
9 * @see <a href="http://tools.ietf.org/html/rfc1867">RFC 1867</a> for
10 * the specification of HTTP file uploads.
12 * @since: 1.7.5
14 public class FileInfo {
15 private final String contentType;
16 private final Date creation;
17 private final String filename;
18 private final long size;
19 private final String md5Hash;
20 private final String gsObjectName;
22 /**
23 * Creates a {@code FileInfo} by providing the associated metadata.
24 * This is done by the API on the developer's behalf.
26 * @param contentType the MIME Content-Type provided in the HTTP header during upload of this
27 * Blob.
28 * @param creation the time and date the blob was uploaded.
29 * @param filename the file included in the Content-Disposition HTTP header during upload of
30 * this Blob.
31 * @param size the size in bytes of this Blob.
32 * @param md5Hash the md5Hash of this Blob.
33 * @param gsObjectName the name of the file written to Google Cloud Storage or null if the file
34 * was not uploaded to Google Cloud Storage.
36 public FileInfo(String contentType, Date creation, String filename, long size, String md5Hash,
37 String gsObjectName) {
38 if (contentType == null) {
39 throw new NullPointerException("contentType must not be null");
41 if (creation == null) {
42 throw new NullPointerException("creation must not be null");
44 if (filename == null) {
45 throw new NullPointerException("filename must not be null");
47 if (md5Hash == null) {
48 throw new NullPointerException("md5Hash must not be null");
51 this.contentType = contentType;
52 this.creation = creation;
53 this.filename = filename;
54 this.size = size;
55 this.md5Hash = md5Hash;
56 this.gsObjectName = gsObjectName;
59 /**
60 * Returns the MIME Content-Type provided in the HTTP header during upload of
61 * this Blob.
63 public String getContentType() {
64 return contentType;
67 /**
68 * Returns the time and date the blob was upload.
70 public Date getCreation() {
71 return creation;
74 /**
75 * Returns the file included in the Content-Disposition HTTP header during
76 * upload of this Blob.
78 public String getFilename() {
79 return filename;
82 /**
83 * Returns the size in bytes of this Blob.
85 public long getSize() {
86 return size;
89 /**
90 * Returns the md5Hash of this Blob.
92 public String getMd5Hash() {
93 return md5Hash;
96 /**
97 * Returns the name of the file written to Google Cloud Storage or null if the file was not
98 * uploaded to Google Cloud Storage. This property is only available for BlobInfos returned by
99 * getUploadedBlobInfos(), as its value is not persisted in the Datastore. Any attempt to
100 * access this property on other BlobInfos will return null.
102 public String getGsObjectName() {
103 return gsObjectName;
106 @Override
107 public boolean equals(Object obj) {
108 if (obj instanceof FileInfo) {
109 FileInfo fi = (FileInfo) obj;
110 return contentType.equals(fi.contentType) &&
111 creation.equals(fi.creation) &&
112 filename.equals(fi.filename) &&
113 size == fi.size &&
114 md5Hash.equals(fi.md5Hash) &&
115 ((gsObjectName == null && fi.gsObjectName == null) ||
116 (gsObjectName != null && gsObjectName.equals(fi.gsObjectName)));
118 return false;
121 @Override
122 public String toString() {
123 StringBuilder builder = new StringBuilder();
124 builder.append("<FileInfo:");
125 builder.append(" contentType = ");
126 builder.append(contentType);
127 builder.append(", creation = ");
128 builder.append(creation.toString());
129 builder.append(", filename = ");
130 builder.append(filename);
131 builder.append(", size = ");
132 builder.append(Long.toString(size));
133 builder.append(", md5Hash = ");
134 builder.append(md5Hash);
135 if (gsObjectName != null) {
136 builder.append(", gsObjectName = ");
137 builder.append(gsObjectName);
139 builder.append(">");
140 return builder.toString();