1 // Copyright 2007 Google Inc. All rights reserved.
3 package com
.google
.appengine
.api
.datastore
;
5 import java
.io
.Serializable
;
6 import java
.util
.Arrays
;
9 * {@code ShortBlob} contains an array of bytes no longer than
10 * {@link DataTypeUtils#MAX_SHORT_BLOB_PROPERTY_LENGTH}. Unlike {@link Blob},
11 * {@code ShortBlobs} are indexed by the datastore and can therefore be
12 * filtered and sorted on in queries. If your data is too large to fit
13 * in a {@code ShortBlob} use {@link Blob} instead.
16 public final class ShortBlob
implements Serializable
, Comparable
<ShortBlob
> {
18 public static final long serialVersionUID
= -3427166602866836472L;
23 * This constructor exists for frameworks (e.g. Google Web Toolkit)
24 * that require it for serialization purposes. It should not be
27 @SuppressWarnings("unused")
33 * Construct a new {@code ShortBlob} with the specified bytes. This
34 * blob cannot be modified after construction.
36 public ShortBlob(byte[] bytes
) {
38 this.bytes
= new byte[bytes
.length
];
39 System
.arraycopy(bytes
, 0, this.bytes
, 0, bytes
.length
);
43 * Return the bytes stored in this {@code ShortBlob}.
45 public byte[] getBytes() {
50 public int hashCode() {
51 return Arrays
.hashCode(bytes
);
55 * Two {@code ShortBlob} objects are considered equal if their contained
56 * bytes match exactly.
59 public boolean equals(Object object
) {
60 if (object
instanceof ShortBlob
) {
61 ShortBlob other
= (ShortBlob
) object
;
62 return Arrays
.equals(bytes
, other
.bytes
);
68 * Simply prints the number of bytes contained in this {@code ShortBlob}.
71 public String
toString() {
72 return "<ShortBlob: " + bytes
.length
+ " bytes>";
76 public int compareTo(ShortBlob other
) {
77 DataTypeTranslator
.ComparableByteArray cba1
= new DataTypeTranslator
.ComparableByteArray(bytes
);
78 DataTypeTranslator
.ComparableByteArray cba2
=
79 new DataTypeTranslator
.ComparableByteArray(other
.bytes
);
80 return cba1
.compareTo(cba2
);