(slop) Translate nulls to empty strings when passed to the StringColumnWriters.

This commit is contained in:
Viktor Lofgren 2024-07-25 18:26:41 +02:00
parent 4123e99469
commit 52a9a0d410

View File

@ -44,6 +44,10 @@ public class StringColumn {
} }
public void put(String value) throws IOException { public void put(String value) throws IOException {
if (null == value) {
value = "";
}
backingColumn.put(value.getBytes()); backingColumn.put(value.getBytes());
} }
@ -93,6 +97,10 @@ public class StringColumn {
} }
public void put(String value) throws IOException { public void put(String value) throws IOException {
if (null == value) {
value = "";
}
assert value.indexOf('\0') == -1 : "Null byte not allowed in cstring"; assert value.indexOf('\0') == -1 : "Null byte not allowed in cstring";
storageWriter.putBytes(value.getBytes()); storageWriter.putBytes(value.getBytes());
storageWriter.putByte((byte) 0); storageWriter.putByte((byte) 0);
@ -155,6 +163,10 @@ public class StringColumn {
} }
public void put(String value) throws IOException { public void put(String value) throws IOException {
if (null == value) {
value = "";
}
assert value.indexOf('\n') == -1 : "Newline not allowed in txtstring"; assert value.indexOf('\n') == -1 : "Newline not allowed in txtstring";
storageWriter.putBytes(value.getBytes()); storageWriter.putBytes(value.getBytes());
@ -176,8 +188,14 @@ public class StringColumn {
public String get() throws IOException { public String get() throws IOException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
byte b; byte b;
while (storageReader.hasRemaining() && (b = storageReader.getByte()) != '\n') { while (storageReader.hasRemaining()) {
sb.append((char) b); b = storageReader.getByte();
if (b == '\n') {
break;
}
else {
sb.append((char) b);
}
} }
return sb.toString(); return sb.toString();
} }