private Set<Long> writeToNode(String path, long uuid, OutputStream out)
            throws KeeperException.NodeExistsException, IOException, UnknownTableException, DroppedTableException {
        ByteArrayOutputStream bufferOut = new ByteArrayOutputStream();
        byte[] tableContent;
        Set<Long> uuids;
        Exception exception = null;

        try {
            // Load the table content from the source
            uuids = _source.loadAndSerialize(uuid, bufferOut);
            tableContent = bufferOut.toByteArray();
        } catch (UnknownTableException | DroppedTableException e) {
            // Record the exception and store the JSON serialized exception as the table content
            exception = e;
            tableContent = JsonHelper.asJson(e).getBytes(Charsets.UTF_8);
            uuids = ImmutableSet.of();
        }

        int nodeContentLength = 4 + 8 * uuids.size() + tableContent.length;  // 4 byte uuid count + 8 bytes per uuid + tableContent
        bufferOut = new ByteArrayOutputStream(nodeContentLength);
        DataOutputStream nodeOut = new DataOutputStream(bufferOut);

        if (exception == null) {
            // Write the actual number of UUIDs associated with the table
            nodeOut.writeInt(uuids.size());
            for (long sourceUuid : uuids) {
                nodeOut.writeLong(sourceUuid);
            }
        } else {
            // Write the exception code (no UUIDs will be written so no size is required)
            nodeOut.writeInt(exception instanceof UnknownTableException ? UNKNOWN_TABLE : DROPPED_TABLE);
        }

        nodeOut.write(tableContent);

        byte[] nodeContent = bufferOut.toByteArray();

        try {
            // Write the content to ZooKeeper
            _curator.create().withMode(CreateMode.PERSISTENT).forPath(path, nodeContent);
            _log.debug("Wrote table for UUID {} to {}", uuid, path);
        } catch (Throwable t) {
            // If the node exists then there was a race condition with another server caching the same table.  Pass
            // to the caller so they can retry reading the value.
            Throwables.propagateIfInstanceOf(t, KeeperException.NodeExistsException.class);
            Throwables.propagateIfInstanceOf(t, IOException.class);
            throw Throwables.propagate(t);
        }

        if (exception != null) {
            // This will always raise the exception
            Throwables.propagateIfPossible(exception, UnknownTableException.class, DroppedTableException.class);
        }

        out.write(tableContent);
        return uuids;
    }
private Set < Long > writeToNode ( String path , long uuid , OutputStream out ) throws KeeperException . NodeExistsException , IOException , UnknownTableException , DroppedTableException { ByteArrayOutputStream bufferOut = new ByteArrayOutputStream ( ) ; byte [ ] tableContent ; Set < Long > uuids ; Exception exception = null ; try { uuids = _source . loadAndSerialize ( uuid , bufferOut ) ; tableContent = bufferOut . toByteArray ( ) ; } catch ( UnknownTableException | DroppedTableException e ) { exception = e ; tableContent = JsonHelper . asJson ( e ) . getBytes ( Charsets . UTF_8 ) ; uuids = ImmutableSet . of ( ) ; } int nodeContentLength = 4 + 8 * uuids . size ( ) + tableContent . length ; bufferOut = new ByteArrayOutputStream ( nodeContentLength ) ; DataOutputStream nodeOut = new DataOutputStream ( bufferOut ) ; if ( exception == null ) { nodeOut . writeInt ( uuids . size ( ) ) ; for ( long sourceUuid : uuids ) { nodeOut . writeLong ( sourceUuid ) ; } } else { nodeOut . writeInt ( exception instanceof UnknownTableException ? UNKNOWN_TABLE : DROPPED_TABLE ) ; } nodeOut . write ( tableContent ) ; byte [ ] nodeContent = bufferOut . toByteArray ( ) ; try { _curator . create ( ) . withMode ( CreateMode . PERSISTENT ) . forPath ( path , nodeContent ) ; _log . debug ( "Wrote table for UUID {} to {}" , uuid , path ) ; } catch ( Throwable t ) { Throwables . propagateIfInstanceOf ( t , KeeperException . NodeExistsException . class ) ; Throwables . propagateIfInstanceOf ( t , IOException . class ) ; throw Throwables . propagate ( t ) ; } if ( exception != null ) { Throwables . propagateIfPossible ( exception , UnknownTableException . class , DroppedTableException . class ) ; } out . write ( tableContent ) ; return uuids ; }
Defers loading the table to the underlying serializer.  Caches the result in ZooKeeper and passes it along
to the caller, just like {@link #loadAndSerialize(long, java.io.OutputStream)}.