diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesReader.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesReader.java
new file mode 100644
index 000000000..3ab9e088e
--- /dev/null
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesReader.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2015 higherfrequencytrading.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package net.openhft.chronicle.hash.serialization.impl;
+
+import net.openhft.chronicle.bytes.Bytes;
+import net.openhft.chronicle.hash.serialization.BytesReader;
+import net.openhft.chronicle.hash.serialization.ListMarshaller;
+import net.openhft.chronicle.hash.serialization.SetMarshaller;
+import net.openhft.chronicle.hash.serialization.StatefulCopyable;
+import net.openhft.chronicle.wire.WireIn;
+import net.openhft.chronicle.wire.WireOut;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+/**
+ * {@link BytesReader} implementation for {@code CharSequence}, for the primary ChronicleMap's key
+ * of value type {@link CharSequenceSizedReader} + {@link CharSequenceSizedWriter} are more
+ * efficient (because don't store the size twice), so this reader is useful in conjunction with
+ * {@link ListMarshaller} or {@link SetMarshaller}.
+ *
+ * @see CharSequenceBytesWriter
+ */
+public enum CharSequenceBytesReader implements BytesReader,
+ StatefulCopyable, EnumMarshallable {
+ INSTANCE;
+
+ @NotNull
+ @Override
+ public CharSequence read(Bytes in, @Nullable CharSequence using) {
+ StringBuilder usingSB;
+ if (using instanceof StringBuilder) {
+ usingSB = (StringBuilder) using;
+ } else {
+ usingSB = new StringBuilder();
+ }
+ if (in.readUtf8(usingSB)) {
+ return usingSB;
+ } else {
+ throw new NullPointerException("BytesReader couldn't read null");
+ }
+ }
+
+ @Override
+ public CharSequenceBytesReader copy() {
+ return INSTANCE;
+ }
+
+ @Override
+ public CharSequenceBytesReader readResolve() {
+ return INSTANCE;
+ }
+}
diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesWriter.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesWriter.java
index 1891ec2c2..d977de8a2 100644
--- a/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesWriter.java
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/CharSequenceBytesWriter.java
@@ -25,10 +25,10 @@ import org.jetbrains.annotations.NotNull;
/**
* {@link BytesWriter} implementation for {@link CharSequence}, for the primary ChronicleMap's
* key or value type {@link CharSequenceSizedWriter} + {@link StringSizedReader} are more
- * effective (because don't store the size twice), so this writer is useful in conjunction with
+ * efficient (because don't store the size twice), so this writer is useful in conjunction with
* {@link ListMarshaller} or {@link SetMarshaller}.
*
- * @see CharSequenceBytesWriter
+ * @see StringBytesReader
*/
public enum CharSequenceBytesWriter
implements BytesWriter, EnumMarshallable {
@@ -36,6 +36,8 @@ public enum CharSequenceBytesWriter
@Override
public void write(Bytes out, @NotNull CharSequence toWrite) {
+ if (toWrite == null)
+ throw new NullPointerException("BytesWriter couldn't write null");
out.writeUtf8(toWrite);
}
diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/StringBytesReader.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/StringBytesReader.java
index d8dc2bb61..c875bffae 100644
--- a/src/main/java/net/openhft/chronicle/hash/serialization/impl/StringBytesReader.java
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/StringBytesReader.java
@@ -31,7 +31,7 @@ import java.io.ObjectInputStream;
/**
* {@link BytesReader} implementation for String, for the primary ChronicleMap's key of value type
- * {@link StringSizedReader} + {@link CharSequenceSizedWriter} are more effective (because don't
+ * {@link StringSizedReader} + {@link CharSequenceSizedWriter} are more efficient (because don't
* store the size twice), so this reader is useful in conjunction with {@link ListMarshaller} or
* {@link SetMarshaller}.
*
@@ -59,9 +59,11 @@ public class StringBytesReader
@NotNull
@Override
public String read(Bytes in, @Nullable String using) {
- sb.setLength(0);
- in.readUtf8(sb);
- return sb.toString();
+ if (in.readUtf8(sb)) {
+ return sb.toString();
+ } else {
+ throw new NullPointerException("BytesReader couldn't read null");
+ }
}
@Override