Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / Blob.java
blobcb4e30b99a543cc41477c0bb0d06416c33e49855
1 /*
2 * Copyright 2007 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
16 package com.google.appengine.api.datastore;
18 import java.io.Serializable;
19 import java.util.Arrays;
21 /**
22 * {@code Blob} contains an array of bytes. This byte array can be no bigger
23 * than 1MB. To store files, particularly files larger than this 1MB limit,
24 * look at the Blobstore API.
27 public final class Blob implements Serializable {
29 private static final long serialVersionUID = 6210713401925622518L;
31 private byte[] bytes;
33 /**
34 * Construct a new {@code Blob} with the specified bytes. Since
35 * {@code Blobs} can be quite large we do not perform a defensive copy of the
36 * provided byte array. It is the programmer's responsibility to avoid
37 * making changes to this array once the {@code Blob} has been constructed.
39 public Blob(byte[] bytes) {
40 this.bytes = bytes;
43 /**
44 * This constructor exists for frameworks (e.g. Google Web Toolkit)
45 * that require it for serialization purposes. It should not be
46 * called explicitly.
48 @SuppressWarnings("unused")
49 private Blob(){
52 /**
53 * Return the bytes stored in this {@code Blob}.
55 public byte[] getBytes() {
56 return bytes;
59 @Override
60 public int hashCode() {
61 return Arrays.hashCode(bytes);
64 /**
65 * Two {@code Blob} objects are considered equal if their contained
66 * bytes match exactly.
68 @Override
69 public boolean equals(Object object) {
70 if (object instanceof Blob) {
71 Blob key = (Blob) object;
72 return Arrays.equals(bytes, key.bytes);
74 return false;
77 /**
78 * Simply prints the number of bytes contained in this {@code Blob}.
80 @Override
81 public String toString() {
82 return "<Blob: " + bytes.length + " bytes>";