summaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2006-08-03 12:59:39 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2006-08-03 12:59:39 +0000
commitb624ca971b748bfbc7c891ed8f154b4270790148 (patch)
tree46453ba94b4168e8a2ccebadff0707282920c979 /src/java/com
parenteba7b7286ca8183c7b7091be1f437946e03367b9 (diff)
downloadjackcess-b624ca971b748bfbc7c891ed8f154b4270790148.tar.gz
jackcess-b624ca971b748bfbc7c891ed8f154b4270790148.zip
add toCharSequence method
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@82 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Column.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java
index d121336..a15bdc1 100644
--- a/src/java/com/healthmarketscience/jackcess/Column.java
+++ b/src/java/com/healthmarketscience/jackcess/Column.java
@@ -553,7 +553,7 @@ public class Column implements Comparable<Column> {
private void writeGUIDValue(ByteBuffer buffer, Object value)
throws IOException
{
- Matcher m = GUID_PATTERN.matcher((CharSequence)value);
+ Matcher m = GUID_PATTERN.matcher(toCharSequence(value));
if(m.matches()) {
ByteUtil.writeHexString(buffer, m.group(1));
ByteUtil.writeHexString(buffer, m.group(2));
@@ -635,7 +635,7 @@ public class Column implements Comparable<Column> {
if (_type == DataType.OLE) {
size += ((byte[]) obj).length;
} else if(_type == DataType.MEMO) {
- byte[] encodedData = encodeUncompressedText((CharSequence) obj).array();
+ byte[] encodedData = encodeUncompressedText(toCharSequence(obj)).array();
size += encodedData.length;
obj = encodedData;
} else if(_type == DataType.TEXT) {
@@ -663,8 +663,7 @@ public class Column implements Comparable<Column> {
} else if (_type == DataType.BINARY) {
buffer.put((byte[]) obj);
} else if (_type == DataType.TEXT) {
- CharSequence text = ((obj instanceof CharSequence) ?
- (CharSequence)obj : obj.toString());
+ CharSequence text = toCharSequence(obj);
int maxChars = size / 2;
if (text.length() > maxChars) {
throw new IOException("Text is too big for column");
@@ -894,6 +893,20 @@ public class Column implements Comparable<Column> {
}
/**
+ * @return an appropriate CharSequence representation of the given object.
+ */
+ private static CharSequence toCharSequence(Object value)
+ {
+ if(value == null) {
+ return null;
+ } else if(value instanceof CharSequence) {
+ return (CharSequence)value;
+ } else {
+ return value.toString();
+ }
+ }
+
+ /**
* Swaps the bytes of the given numeric in place.
*/
private static void fixNumericByteOrder(byte[] bytes)