@Override public E decode(InputStream from) throws IOException { return decoder.decode(from); }
@Override public void encode(E obj, OutputStream into) throws IOException { encoder.encode(obj, into); } }
@Test public void test() throws IOException { String obj = "Foo"; StreamingEncoder<String> encoder = new GZIPStreamingEncoderWrapper<>(new StreamingSerializableCodec<>()); StreamingDecoder<String> decoder = new GZIPStreamingDecoderWrapper<>(new StreamingSerializableCodec<>()); ByteArrayOutputStream bos=new ByteArrayOutputStream(); encoder.encode(obj, bos); ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray()); String decoded = decoder.decode(bis); assertEquals(obj, decoded); } }
@Test public void test() throws IOException { String obj = "Foo"; StreamingSerializableCodec<String> instance = new StreamingSerializableCodec<>(); ByteArrayOutputStream bos=new ByteArrayOutputStream(); instance.encode(obj, bos); ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray()); String decoded = instance.decode(bis); assertEquals(obj, decoded); } }
@Override public E decode(InputStream from) throws IOException { return decoder.decode(from); }
@Override public void encode(E obj, OutputStream into) throws IOException { encoder.encode(obj, into); } }
@Override public E decode(InputStream from) throws IOException { GZIPInputStream gis=new GZIPInputStream(from); return wrapped.decode(gis); } }
@Override public void encode(E obj, OutputStream into) throws IOException { GZIPOutputStream gos=new GZIPOutputStream(into); wrapped.encode(obj, gos); gos.finish(); } }
@Override public E decode(InputStream from) throws IOException { GZIPInputStream gis=new GZIPInputStream(from); return wrapped.decode(gis); } }
@Override public void encode(E obj, OutputStream into) throws IOException { GZIPOutputStream gos=new GZIPOutputStream(into); wrapped.encode(obj, gos); gos.finish(); } }
@Override public E decode(byte[] bytes) { ByteArrayInputStream bis=new ByteArrayInputStream(bytes); try { return wrapped.decode(bis); } catch (IOException e) { if(logger.isWarnEnabled()) logger.warn("Couldn't decode!", e); } return null; } }
@Override @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull") public byte[] encode(E object) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { wrapped.encode(object, bos); return bos.toByteArray(); } catch (IOException e) { if(logger.isWarnEnabled()) logger.warn("Exception while encoding {}!", object, e); } return null; } }
@Override public E decode(byte[] bytes) { ByteArrayInputStream bis=new ByteArrayInputStream(bytes); try { return wrapped.decode(bis); } catch (IOException e) { if(logger.isWarnEnabled()) logger.warn("Couldn't decode!", e); } return null; } }
@Override @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull") public byte[] encode(E object) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { wrapped.encode(object, bos); return bos.toByteArray(); } catch (IOException e) { if(logger.isWarnEnabled()) logger.warn("Exception while encoding {}!", object, e); } return null; } }