Permalink
Browse files

MODE-1703 Minor improvements

Based upon feedback, two sections of commented-out code were removed (they'd been there
for some time) and the Code.Externalizer methods were changed to use constants rather
than magic numbers for the types of the Code classes.
  • Loading branch information...
1 parent c9a3b10 commit 25eff0cbb424466763d0809c642850a66f87e61e @rhauch rhauch committed Nov 12, 2012
@@ -73,17 +73,19 @@ public String toString() {
public static class Externalizer extends SchematicExternalizer<Code> {
private static final long serialVersionUID = 1L;
+ private static final int CODE_WITHOUT_SCOPE_TYPE = 1;
+ private static final int CODE_WITH_SCOPE_TYPE = 2;
@Override
public void writeObject( ObjectOutput output,
Code value ) throws IOException {
if (value instanceof CodeWithScope) {
CodeWithScope withScope = (CodeWithScope)value;
- output.writeInt(2);
+ output.writeInt(CODE_WITH_SCOPE_TYPE);
output.writeUTF(withScope.getCode());
output.writeObject(withScope.getScope());
} else {
- output.writeInt(1);
+ output.writeInt(CODE_WITHOUT_SCOPE_TYPE);
output.writeUTF(value.getCode());
}
}
@@ -92,10 +94,10 @@ public void writeObject( ObjectOutput output,
public Code readObject( ObjectInput input ) throws IOException, ClassNotFoundException {
int type = input.readInt();
switch (type) {
- case 1:
+ case CODE_WITHOUT_SCOPE_TYPE:
String code = input.readUTF();
return new Code(code);
- case 2:
+ case CODE_WITH_SCOPE_TYPE:
code = input.readUTF();
Document scope = (Document)input.readObject();
return new CodeWithScope(code, scope);
@@ -56,15 +56,7 @@ public Document read( InputStream stream ) throws IOException {
// Create an object so that this reader is thread safe ...
DocumentValueFactory valueFactory = VALUE_FACTORY;
Reader reader = new Reader(new BsonDataInput(new DataInputStream(stream)), valueFactory);
- // try {
reader.startDocument();
- // } catch (IOException e) {
- // Json.writePretty(reader.endDocument(), System.err);
- // throw e;
- // } catch (RuntimeException e) {
- // Json.writePretty(reader.endDocument(), System.err);
- // throw e;
- // }
return reader.endDocument();
}
@@ -94,15 +86,7 @@ public Array readArray( InputStream stream ) throws IOException {
// Create an object so that this reader is thread safe ...
DocumentValueFactory valueFactory = VALUE_FACTORY;
Reader reader = new Reader(new BsonDataInput(new DataInputStream(stream)), valueFactory);
- // try {
reader.startArray();
- // } catch (IOException e) {
- // Json.writePretty(reader.endDocument(), System.err);
- // throw e;
- // } catch (RuntimeException e) {
- // Json.writePretty(reader.endDocument(), System.err);
- // throw e;
- // }
return (Array)reader.endDocument();
}

0 comments on commit 25eff0c

Please sign in to comment.