@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); } }
public void restore(final DataInputStreamExtended inputImpl) throws IOException { state = inputImpl.readEncodable(Data.class); }
@Before public void setUp() throws Exception { final PipedInputStream pipedInputStream = new PipedInputStream(); final PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream); outputImpl = new DataOutputStreamExtended(pipedOutputStream); inputImpl = new DataInputStreamExtended(pipedInputStream); }
@Test public void encodeAndDecodeNullObjectArray() throws IOException { outputImpl.writeEncodables(null); final Encodable[] objects = inputImpl.readEncodables(Encodable.class); assertThat(objects, is(nullValue())); }
@Test public void encodeAndDecodeString() throws IOException { outputImpl.writeUTF("test"); outputImpl.writeUTF(""); outputImpl.writeUTF("second"); assertThat(inputImpl.readUTF(), is(equalTo("test"))); assertThat(inputImpl.readUTF(), is(equalTo(""))); assertThat(inputImpl.readUTF(), is(equalTo("second"))); }
@Test public void encodeAndDecodeStringArray() throws IOException { final String[] list = { "one", "two", "three" }; outputImpl.writeUTFs(list); final String[] returnedList = inputImpl.readUTFs(); assertThat(returnedList.length, is(equalTo(list.length))); assertThat(returnedList[0], is(equalTo(list[0]))); assertThat(returnedList[1], is(equalTo(list[1]))); assertThat(returnedList[2], is(equalTo(list[2]))); }
@Test public void encodeAndDecodeBoolean() throws IOException { outputImpl.writeBoolean(true); outputImpl.writeBoolean(false); assertThat(inputImpl.readBoolean(), is(equalTo(true))); assertThat(inputImpl.readBoolean(), is(equalTo(false))); }
@Test public void encodeAndDecodeByteArray() throws IOException { final byte[] bytes = { 3, 76, -1, 21 }; outputImpl.writeBytes(bytes); final byte[] decodedBytes = inputImpl.readBytes(); assertThatArraysEqual(bytes, decodedBytes); }
@Test public void encodeAndDecodeNullObject() throws IOException { outputImpl.writeEncodable(null); final Object object = inputImpl.readEncodable(Object.class); assertThat(object, is(nullValue())); }
@Override public void connect() throws IOException { super.connect(); this.input = new DataInputStreamExtended(getTransport().getInputStream()); this.output = new DataOutputStreamExtended(getTransport().getOutputStream()); if (debugging) { this.input = new DebugDataInputExtended(input); this.output = new DebugDataOutputExtended(output); } }
@Test public void encodeAndDecodeObjectArray() throws IOException { final EncodableObject[] array = new EncodableObject[] { new EncodableObject(), new EncodableObject(), new EncodableObject() }; outputImpl.writeEncodables(array); final Encodable[] objects = inputImpl.readEncodables(Encodable.class); assertThat(objects.length, is(3)); final EncodableObject encodeableObject = (EncodableObject) objects[2]; 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); }
@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"))); }