App Engine Python SDK version 1.8.4
[gae.git] / java / src / main / com / google / appengine / api / conversion / Asset.java
blobd8314db7368b70ecc0e668dbc2a787cbd3e8afb0
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.conversion;
5 import com.google.common.base.Objects;
6 import com.google.common.base.Preconditions;
8 /**
9 * An immutable asset for conversion. A conversion document must contain at
10 * least one asset, typically the document contents. Additional asset can be
11 * referenced from the main asset, such as in case of images or CSS files from
12 * HTML documents.
15 public final class Asset {
17 private final String mimeType;
18 private final byte[] data; private final String name;
20 /**
21 * Constructs an asset.
23 * @param mimeType the asset's mime type
24 * @param data the asset's data
26 public Asset(String mimeType, byte[] data) {
27 this(mimeType, data, null);
30 /**
31 * Constructs an asset.
33 * @param mimeType the asset's mime type
34 * @param data the asset's data
35 * @param name the asset's name, or null if none
37 public Asset(String mimeType, byte[] data, String name) {
38 this.mimeType = Preconditions.checkNotNull(mimeType).toLowerCase();
39 this.data = data;
40 this.name = name;
43 /**
44 * Returns the asset's mime type.
46 public String getMimeType() {
47 return mimeType;
50 /**
51 * Returns the asset's data.
53 public byte[] getData() {
54 return data;
57 /**
58 * Returns the asset's name, or null if not present.
60 public String getName() {
61 return name;
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) {
67 return true;
69 if (o == null || getClass() != o.getClass()) {
70 return false;
73 Asset other = ((Asset) o);
74 return Objects.equal(mimeType, other.getMimeType())
75 && Objects.deepEquals(data, other.getData())
76 && Objects.equal(name, other.getName());
79 @Override
80 public int hashCode() {
81 return Objects.hashCode(mimeType, data, name);