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
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
16 package com
.google
.appengine
.api
.datastore
;
18 import java
.io
.Serializable
;
19 import java
.util
.Arrays
;
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;
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
) {
44 * This constructor exists for frameworks (e.g. Google Web Toolkit)
45 * that require it for serialization purposes. It should not be
48 @SuppressWarnings("unused")
53 * Return the bytes stored in this {@code Blob}.
55 public byte[] getBytes() {
60 public int hashCode() {
61 return Arrays
.hashCode(bytes
);
65 * Two {@code Blob} objects are considered equal if their contained
66 * bytes match exactly.
69 public boolean equals(Object object
) {
70 if (object
instanceof Blob
) {
71 Blob key
= (Blob
) object
;
72 return Arrays
.equals(bytes
, key
.bytes
);
78 * Simply prints the number of bytes contained in this {@code Blob}.
81 public String
toString() {
82 return "<Blob: " + bytes
.length
+ " bytes>";