@Override
    public <T> ISignalWriteStream putBinary(final String cacheKey, final T jsonObject, final long timeToLive)
            throws IOException {
        final CacheEntry entry = new CacheEntry();
        entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000));
        entry.setHead(JSON_MAPPER.writeValueAsString(jsonObject));

        final IApimanBuffer data = bufferFactory.createBuffer();
        return new ISignalWriteStream() {
            boolean finished = false;
            boolean aborted = false;

            @Override
            public void abort(Throwable t) {
                finished = true;
                aborted = false;
            }

            @Override
            public boolean isFinished() {
                return finished;
            }

            @Override
            public void write(IApimanBuffer chunk) {
                data.append(chunk);
            }

            @Override
            public void end() {
                if (!aborted) {
                    entry.setData(Base64.encodeBase64String(data.getBytes()));
                    try {
                        getStore().put(cacheKey, entry);
                    } catch (Throwable e) {
                        LOGGER.error("Error writing binary cache entry with key: {}", cacheKey, e);
                    }
                }
                finished = true;
            }
        };
    }
@ Override public < T > ISignalWriteStream putBinary ( final String cacheKey , final T jsonObject , final long timeToLive ) throws IOException { final CacheEntry entry = new CacheEntry ( ) ; entry . setExpiresOn ( System . currentTimeMillis ( ) + ( timeToLive * 1000 ) ) ; entry . setHead ( JSON_MAPPER . writeValueAsString ( jsonObject ) ) ; final IApimanBuffer data = bufferFactory . createBuffer ( ) ; return new ISignalWriteStream ( ) { boolean finished = false ; boolean aborted = false ; @ Override public void abort ( Throwable t ) { finished = true ; aborted = false ; } @ Override public boolean isFinished ( ) { return finished ; } @ Override public void write ( IApimanBuffer chunk ) { data . append ( chunk ) ; } @ Override public void end ( ) { if ( ! aborted ) { entry . setData ( Base64 . encodeBase64String ( data . getBytes ( ) ) ) ; try { getStore ( ) . put ( cacheKey , entry ) ; } catch ( Throwable e ) { LOGGER . error ( "Error writing binary cache entry with key: {}" , cacheKey , e ) ; } } finished = true ; } } ; }
@see ICacheStoreComponent#putBinary(String, Object, long)