-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathBinaryObject.java
More file actions
36 lines (29 loc) · 881 Bytes
/
BinaryObject.java
File metadata and controls
36 lines (29 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */
package org.restsql.core;
import com.sun.jersey.core.util.Base64;
/**
* Wraps a byte array for input/output to a binary type column. String representation is expected in base64.
*
* @author Mark Sawers
*/
public class BinaryObject {
private byte[] bytes;
public BinaryObject(byte[] bytes) {
this.bytes = bytes;
}
public byte[] getBytes() {
return bytes;
}
/** Generates base64 string representation. */
public String toString() {
return new String(Base64.encode(bytes));
}
/** Returns true if string is base64 encoded. */
public static boolean isStringBase64(String string) {
return Base64.isBase64(string);
}
/** Parses bytes from base64 string representation. */
public static BinaryObject fromString(String string) {
return new BinaryObject(Base64.decode(string));
}
}