public void restore(final DataInputStreamExtended inputImpl) throws IOException { state = inputImpl.readEncodable(Data.class); }
@Override public Oid deString(final String oidStr) { final char[] oidCharArray = oidStr.toCharArray(); byte[] oidBytes; try { oidBytes = Hex.decodeHex(oidCharArray); final ByteArrayInputStream bais = new ByteArrayInputStream(oidBytes); final DataInputStreamExtended inputImpl = new DataInputStreamExtended(bais); return inputImpl.readEncodable(Oid.class); } catch (final IOException ex) { throw new IsisException("Failed to read object", ex); } catch (final DecoderException ex) { throw new IsisException("Failed to hex decode object", ex); } }
@Test public void encodeAndDecodeNullObject() throws IOException { outputImpl.writeEncodable(null); final Object object = inputImpl.readEncodable(Object.class); assertThat(object, is(nullValue())); }
@Test public void encodeAndDecodeObject() throws IOException { outputImpl.writeEncodable(new EncodableObject()); final Object object = inputImpl.readEncodable(Object.class); assertThat(object, is(instanceOf(EncodableObject.class))); final EncodableObject encodeableObject = (EncodableObject) object; assertThat(encodeableObject.field, is(equalTo("test field"))); }
@Test public void shouldRoundTrip() throws IOException { final PipedInputStream pipedInputStream = new PipedInputStream(); final PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream); final DataOutputStreamExtended outputImpl = new DataOutputStreamExtended(pipedOutputStream); final DataInputStreamExtended inputImpl = new DataInputStreamExtended(pipedInputStream); outputImpl.writeEncodable(encodable); final Object decodedEncodable = inputImpl.readEncodable(Object.class); assertRoundtripped(decodedEncodable, encodable); }