@Override public void encode(E obj, OutputStream into) throws IOException { encoder.encode(obj, into); } }
@Override public void encode(E obj, OutputStream into) throws IOException { encoder.encode(obj, into); } }
@Override public void encode(E obj, OutputStream into) throws IOException { GZIPOutputStream gos=new GZIPOutputStream(into); wrapped.encode(obj, gos); gos.finish(); } }
@Override public void encode(E obj, OutputStream into) throws IOException { GZIPOutputStream gos=new GZIPOutputStream(into); wrapped.encode(obj, gos); gos.finish(); } }
@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 @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; } }
@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); } }