Example usage for java.io DataOutputStream write

List of usage examples for java.io DataOutputStream write

Introduction

In this page you can find the example usage for java.io DataOutputStream write.

Prototype

public synchronized void write(int b) throws IOException 

Source Link

Document

Writes the specified byte (the low eight bits of the argument b) to the underlying output stream.

Usage

From source file:org.echocat.jomon.net.dns.DnsServer.java

byte[] doAXFR(Name name, Message query, TSIG tsig, TSIGRecord qtsig, Socket s) {
    final Zone zone = _znames.get(name);
    boolean first = true;
    if (zone == null) {
        return errorMessage(query, Rcode.REFUSED);
    }/*from www. j  a  va 2 s.  c om*/
    final Iterator<?> it = zone.AXFR();
    try {
        final DataOutputStream dataOut;
        dataOut = new DataOutputStream(s.getOutputStream());
        final int id = query.getHeader().getID();
        while (it.hasNext()) {
            final RRset rrset = (RRset) it.next();
            final Message response = new Message(id);
            final Header header = response.getHeader();
            header.setFlag(Flags.QR);
            header.setFlag(Flags.AA);
            addRRset(rrset.getName(), response, rrset, Section.ANSWER, FLAG_DNSSECOK);
            if (tsig != null) {
                tsig.applyStream(response, qtsig, first);
                qtsig = response.getTSIG();
            }
            first = false;
            final byte[] out = response.toWire();
            dataOut.writeShort(out.length);
            dataOut.write(out);
        }
    } catch (final IOException ignored) {
        LOG.info("AXFR failed");
    }
    closeQuietly(s);
    return null;
}

From source file:com.smartbear.collaborator.issue.IssueRest.java

/**
 * Uploads zip file of raw files to Collaborator server
 * //from   w w w.j av a  2s.  co m
 * @param targetZipFile
 * @throws Exception
 */
private void uploadRawFilesToCollab(java.io.File targetZipFile) throws Exception {
    HttpURLConnection httpUrlConnection = null;
    try {

        String crlf = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";

        URL url = new URL(configModel.getUrl() + URI_COLAB_UPLOAD);
        httpUrlConnection = (HttpURLConnection) url.openConnection();
        httpUrlConnection.setUseCaches(false);
        httpUrlConnection.setDoOutput(true);

        httpUrlConnection.setRequestMethod("POST");
        httpUrlConnection.setRequestProperty("Connection", "Keep-Alive");
        httpUrlConnection.setRequestProperty("Cache-Control", "no-cache");
        httpUrlConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);

        String loginCookie = "CodeCollaboratorLogin=" + configModel.getLogin();
        String ticketCookie = "CodeCollaboratorTicketId=" + configModel.getAuthTicket();

        httpUrlConnection.setRequestProperty("Cookie", loginCookie + "," + ticketCookie);

        DataOutputStream request = new DataOutputStream(httpUrlConnection.getOutputStream());

        request.writeBytes(twoHyphens + boundary + crlf);
        request.writeBytes("Content-Disposition: form-data; name=\"file\";filename=\"" + targetZipFile.getName()
                + "\"" + crlf);
        request.writeBytes("Content-Type: application/x-zip-compressed" + crlf);

        request.writeBytes(crlf);

        InputStream fileInStream = new FileInputStream(targetZipFile);
        request.write(IOUtils.toByteArray(fileInStream));

        request.writeBytes(crlf);
        request.writeBytes(twoHyphens + boundary + twoHyphens + crlf);

        request.flush();
        request.close();

        if (httpUrlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new Exception();
        }

    } catch (Exception e) {
        LOGGER.error(e);
        throw new Exception(
                "Can't upload raw versions to Collaborator Server. Check plugin collaborator configuration (url, login, password).",
                e);
    } finally {
        if (httpUrlConnection != null) {
            httpUrlConnection.disconnect();
        }
    }
}

From source file:com.trifork.riak.RiakClient.java

public ByteString[] store(RiakObject[] values, RequestMeta meta) throws IOException {

    RiakConnection c = getConnection();/*w  ww .  j a v  a 2 s  . com*/
    try {
        BulkReader reader = new BulkReader(c, values.length);
        Thread worker = new Thread(reader);
        worker.start();

        DataOutputStream dout = c.getOutputStream();

        for (int i = 0; i < values.length; i++) {
            RiakObject value = values[i];

            RPB.RpbPutReq.Builder builder = RPB.RpbPutReq.newBuilder().setBucket(value.getBucketBS())
                    .setKey(value.getKeyBS()).setContent(value.buildContent());

            if (value.getVclock() != null) {
                builder.setVclock(value.getVclock());
            }

            builder.setReturnBody(false);

            if (meta != null) {

                if (meta.writeQuorum != null) {
                    builder.setW(meta.writeQuorum.intValue());
                }

                if (meta.durableWriteQuorum != null) {
                    builder.setDw(meta.durableWriteQuorum.intValue());
                }
            }

            RpbPutReq req = builder.build();

            int len = req.getSerializedSize();
            dout.writeInt(len + 1);
            dout.write(MSG_PutReq);
            req.writeTo(dout);
        }

        dout.flush();

        try {
            worker.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return reader.vclocks;
    } finally {
        release(c);
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.onlineTests.TestsManagementAction.java

public ActionForward showImage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws FenixActionException {
    final String exerciseCode = getStringFromRequest(request, "exerciseCode");
    final Integer imgCode = getCodeFromRequest(request, "imgCode");
    final String imgTypeString = request.getParameter("imgType");
    final String studentCode = getStringFromRequest(request, "studentCode");
    final String optionShuffle = request.getParameter("optionShuffle");
    final String testCode = getStringFromRequest(request, "testCode");
    final Integer itemIndex = getCodeFromRequest(request, "item");
    final Integer feedbackCode = getCodeFromRequest(request, "feedbackCode");
    String img = null;// w  w  w. j  av  a 2 s.  c o m
    if (studentCode != null && testCode != null) {
        try {
            img = ReadStudentTestQuestionImage.run(studentCode, testCode, exerciseCode, imgCode, feedbackCode,
                    itemIndex);
        } catch (FenixServiceException e) {
            throw new FenixActionException(e);
        }
    } else if (optionShuffle != null && !Strings.isNullOrEmpty(testCode)) {
        try {
            img = ReadQuestionImage.run(testCode, exerciseCode, optionShuffle, imgCode, feedbackCode);
        } catch (FenixServiceException e) {
            throw new FenixActionException(e);
        }
    } else {

        try {
            img = ReadQuestionImage.run(exerciseCode, imgCode, feedbackCode, itemIndex);
        } catch (FenixServiceException e) {
            throw new FenixActionException(e);
        }
    }
    byte[] imageData = BaseEncoding.base64().decode(img);
    try {
        response.reset();
        response.setContentType(imgTypeString);
        response.setContentLength(imageData.length);
        response.setBufferSize(imageData.length);
        String imageName = "image" + exerciseCode + imgCode + "."
                + imgTypeString.substring(imgTypeString.lastIndexOf("/") + 1, imgTypeString.length());
        response.setHeader("Content-disposition", "attachment; filename=" + imageName);
        DataOutputStream dataOut = new DataOutputStream(response.getOutputStream());
        dataOut.write(imageData);
        response.flushBuffer();
    } catch (java.io.IOException e) {
        throw new FenixActionException(e);
    }
    return null;
}

From source file:com.wso2telco.dep.mediator.RequestExecutor.java

/**
 * Make tokenrequest./*from  ww  w .j a  v a2s .  c o  m*/
 *
 * @param tokenurl
 *            the tokenurl
 * @param urlParameters
 *            the url parameters
 * @param authheader
 *            the authheader
 * @return the string
 */
protected String makeTokenrequest(String tokenurl, String urlParameters, String authheader,
        MessageContext messageContext) {

    ICallresponse icallresponse = null;
    String retStr = "";

    URL neturl;
    HttpURLConnection connection = null;

    log.info("url : " + tokenurl + " | urlParameters : " + urlParameters + " | authheader : " + authheader
            + " Request ID: " + UID.getRequestID(messageContext));

    if ((tokenurl != null && tokenurl.length() > 0) && (urlParameters != null && urlParameters.length() > 0)
            && (authheader != null && authheader.length() > 0)) {
        try {

            byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
            int postDataLength = postData.length;
            URL url = new URL(tokenurl);

            connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setInstanceFollowRedirects(false);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Authorization", authheader);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("charset", "utf-8");
            connection.setRequestProperty("Content-Length", Integer.toString(postDataLength));
            connection.setUseCaches(false);

            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
            wr.write(postData);
            wr.flush();
            wr.close();

            if ((connection.getResponseCode() != 200) && (connection.getResponseCode() != 201)
                    && (connection.getResponseCode() != 400) && (connection.getResponseCode() != 401)) {
                log.info("connection.getResponseMessage() : " + connection.getResponseMessage());
                throw new RuntimeException("Failed : HTTP error code : " + connection.getResponseCode());
            }

            InputStream is = null;
            if ((connection.getResponseCode() == 200) || (connection.getResponseCode() == 201)) {
                is = connection.getInputStream();
            } else {
                is = connection.getErrorStream();
            }

            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String output;
            while ((output = br.readLine()) != null) {
                retStr += output;
            }
            br.close();
        } catch (Exception e) {
            log.error("[WSRequestService ], makerequest, " + e.getMessage(), e);
            return null;
        } finally {

            if (connection != null) {
                connection.disconnect();
            }
        }
    } else {
        log.error("Token refresh details are invalid.");
    }

    return retStr;
}

From source file:com.jivesoftware.os.amza.service.AmzaService.java

private boolean streamOnline(RingMember ringMember, VersionedPartitionName versionedPartitionName,
        long highestTransactionId, long leadershipToken, long limit, DataOutputStream dos, MutableLong bytes,
        HighwaterStorage highwaterStorage, PartitionStripe.RowStreamer streamer) throws Exception {

    ackWaters.set(ringMember, versionedPartitionName, highestTransactionId, leadershipToken);
    dos.writeLong(leadershipToken);/*  ww  w  . ja  va2s.c  o m*/
    dos.writeLong(versionedPartitionName.getPartitionVersion());
    dos.writeByte(1); // fully online
    bytes.increment();
    RingTopology ring = ringStoreReader.getRing(versionedPartitionName.getPartitionName().getRingName(), -1);
    for (int i = 0; i < ring.entries.size(); i++) {
        if (ring.rootMemberIndex != i) {
            RingMemberAndHost entry = ring.entries.get(i);
            long highwatermark = highwaterStorage.get(entry.ringMember, versionedPartitionName);
            byte[] ringMemberBytes = entry.ringMember.toBytes();
            dos.writeByte(1);
            dos.writeInt(ringMemberBytes.length);
            dos.write(ringMemberBytes);
            dos.writeLong(highwatermark);
            bytes.add(1 + 4 + ringMemberBytes.length + 8);
        }
    }

    dos.writeByte(0); // last entry marker
    bytes.increment();

    long[] limited = new long[1];
    long[] lastRowTxId = { -1 };
    boolean streamedToEnd = streamer.stream((rowFP, rowTxId, rowType, row) -> {
        if (limited[0] >= limit && lastRowTxId[0] < rowTxId) {
            return false;
        }
        lastRowTxId[0] = rowTxId;
        dos.writeByte(1);
        dos.writeLong(rowTxId);
        dos.writeByte(rowType.toByte());
        dos.writeInt(row.length);
        dos.write(row);
        bytes.add(1 + 8 + 1 + 4 + row.length);
        limited[0]++;
        return true;
    });

    dos.writeByte(0); // last entry marker
    bytes.increment();
    dos.writeByte(streamedToEnd ? 1 : 0); // streamedToEnd marker
    bytes.increment();
    return false;
}

From source file:org.apache.jackrabbit.core.persistence.util.Serializer.java

/**
 * Serializes the specified <code>PropertyState</code> object to the given
 * binary <code>stream</code>. Binary values are stored in the specified
 * <code>BLOBStore</code>./*from   w  ww. j  ava 2 s  . c  om*/
 *
 * @param state     <code>state</code> to serialize
 * @param stream    the stream where the <code>state</code> should be
 *                  serialized to
 * @param blobStore handler for BLOB data
 * @throws Exception if an error occurs during the serialization
 * @see #deserialize(PropertyState, InputStream,BLOBStore)
 */
public static void serialize(PropertyState state, OutputStream stream, BLOBStore blobStore) throws Exception {
    DataOutputStream out = new DataOutputStream(stream);

    // type
    out.writeInt(state.getType());
    // multiValued
    out.writeBoolean(state.isMultiValued());
    // definitionId
    out.writeUTF("");
    // modCount
    out.writeShort(state.getModCount());
    // values
    InternalValue[] values = state.getValues();
    out.writeInt(values.length); // count
    for (int i = 0; i < values.length; i++) {
        InternalValue val = values[i];
        if (state.getType() == PropertyType.BINARY) {
            // special handling required for binary value:
            // put binary value in BLOB store
            InputStream in = val.getStream();
            String blobId = blobStore.createId(state.getPropertyId(), i);
            try {
                blobStore.put(blobId, in, val.getLength());
            } finally {
                IOUtils.closeQuietly(in);
            }
            // store id of BLOB as property value
            out.writeUTF(blobId); // value
            // replace value instance with value backed by resource
            // in BLOB store and discard old value instance (e.g. temp file)
            if (blobStore instanceof ResourceBasedBLOBStore) {
                // optimization: if the BLOB store is resource-based
                // retrieve the resource directly rather than having
                // to read the BLOB from an input stream
                FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(blobId);
                values[i] = InternalValue.create(fsRes);
            } else {
                in = blobStore.get(blobId);
                try {
                    values[i] = InternalValue.create(in);
                } finally {
                    IOUtils.closeQuietly(in);
                }
            }
            val.discard();
        } else {
            /**
             * because writeUTF(String) has a size limit of 65k,
             * Strings are serialized as <length><byte[]>
             */
            //out.writeUTF(val.toString());   // value
            byte[] bytes = val.toString().getBytes(ENCODING);
            out.writeInt(bytes.length); // lenght of byte[]
            out.write(bytes); // byte[]
        }
    }
}

From source file:GifEncoder.java

private void a(int ai[], int j, DataOutputStream dataoutputstream) throws Exception {
    try {//from  w w w  .j a  va 2  s.c om
        boolean flag2 = false;
        int l;
        int j3 = (1 << (l = j + 1)) - 1;
        int i2 = (1 << j) + 2;
        byte abyte0[] = new byte[255];
        int ai1[] = new int[4096];
        int ai2[] = new int[4096];
        int ai3[] = new int[4096];
        int ai4[] = new int[i2];
        int k;
        for (k = 0; k < i2; k++) {
            ai4[k] = 0xffffffff | k;
            ai3[k] = -1;
        }

        for (; k < 4096; k++) {
            ai3[k] = -1;
        }

        System.arraycopy(ai3, 0, ai1, 0, 4096);
        System.arraycopy(ai3, 0, ai2, 0, 4096);
        System.arraycopy(ai4, 0, ai1, 0, i2);
        int j1 = ai[0];
        k = 1;
        boolean flag1 = false;
        int j2 = 0;
        int k2 = (1 << l) - 1;
        boolean flag = true;
        int i3 = 0;
        int i1 = 0;
        j2 |= 1 << j + i3;
        for (i3 += l; i3 >= 8;) {
            try {
                abyte0[i1++] = (byte) j2;
            } catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception) {
                dataoutputstream.writeByte(255);
                dataoutputstream.write(abyte0);
                abyte0[i1 = 0] = (byte) j2;
                i1++;
            }
            i3 -= 8;
            j2 >>= 8;
        }

        try {
            do {
                int k1;
                int l1 = j1 << 16 | (k1 = ai[k++]);
                int k3;
                for (k3 = j1; ai1[k3] != l1 && ai2[k3] >= 0; k3 = ai2[k3]) {
                }
                if (ai1[k3] != l1) {
                    j2 |= j1 << i3;
                    for (i3 += l; i3 >= 8;) {
                        try {
                            abyte0[i1++] = (byte) j2;
                        } catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception1) {
                            dataoutputstream.writeByte(255);
                            dataoutputstream.write(abyte0);
                            abyte0[i1 = 0] = (byte) j2;
                            i1++;
                        }
                        i3 -= 8;
                        j2 >>= 8;
                    }

                    if (i2 > j3) {
                        l++;
                        j3 = (j3 << 1) + 1;
                    }
                    try {
                        ai2[k3] = i2;
                        ai1[i2++] = j1 << 16 | k1;
                        j1 = k1;
                    } catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception2) {
                        j1 = k1;
                        l--;
                        j2 |= 1 << j + i3;
                        for (i3 += l; i3 >= 8;) {
                            try {
                                abyte0[i1++] = (byte) j2;
                            } catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception5) {
                                dataoutputstream.writeByte(255);
                                dataoutputstream.write(abyte0);
                                abyte0[i1 = 0] = (byte) j2;
                                i1++;
                            }
                            i3 -= 8;
                            j2 >>= 8;
                        }

                        j3 = (1 << (l = j + 1)) - 1;
                        i2 = (1 << j) + 2;
                        int l2 = (1 << l) - 1;
                        System.arraycopy(ai3, 0, ai1, 0, 4096);
                        System.arraycopy(ai3, 0, ai2, 0, 4096);
                        System.arraycopy(ai4, 0, ai1, 0, i2);
                    }
                } else {
                    j1 = k3;
                }
            } while (true);
        } catch (Exception exception) {
            j2 |= j1 << i3;
        }
        for (i3 += l; i3 >= 8;) {
            try {
                abyte0[i1++] = (byte) j2;
            } catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception3) {
                dataoutputstream.writeByte(255);
                dataoutputstream.write(abyte0);
                abyte0[i1 = 0] = (byte) j2;
                i1++;
            }
            i3 -= 8;
            j2 >>= 8;
        }

        j2 |= (1 << j) + 1 << i3;
        for (i3 += l; i3 > 0;) {
            try {
                abyte0[i1++] = (byte) j2;
            } catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception4) {
                dataoutputstream.writeByte(255);
                dataoutputstream.write(abyte0);
                abyte0[i1 = 0] = (byte) j2;
                i1++;
            }
            i3 -= 8;
            j2 >>= 8;
        }

        dataoutputstream.writeByte(i1);
        dataoutputstream.write(abyte0, 0, i1);
        dataoutputstream.writeByte(0);
        return;
    } catch (Exception e) {
    }
}

From source file:com.basho.riak.pbc.RiakClient.java

public ByteString[] store(RiakObject[] values, RequestMeta meta) throws IOException {

    RiakConnection c = getConnection();//from w  w  w  .j  av  a 2 s  .c om
    try {
        BulkReader reader = new BulkReader(c, values.length);
        Thread worker = new Thread(reader);
        worker.start();

        DataOutputStream dout = c.getOutputStream();

        for (int i = 0; i < values.length; i++) {
            RiakObject value = values[i];

            RiakKvPB.RpbPutReq.Builder builder = RiakKvPB.RpbPutReq.newBuilder().setBucket(value.getBucketBS())
                    .setKey(value.getKeyBS()).setContent(value.buildContent());

            if (value.getVclock() != null) {
                builder.setVclock(value.getVclock());
            }

            builder.setReturnBody(true);

            if (meta != null) {

                if (meta.writeQuorum != null) {
                    builder.setW(meta.writeQuorum.intValue());
                }

                if (meta.durableWriteQuorum != null) {
                    builder.setDw(meta.durableWriteQuorum.intValue());
                }
            }

            RpbPutReq req = builder.build();

            int len = req.getSerializedSize();
            dout.writeInt(len + 1);
            dout.write(MSG_PutReq);
            req.writeTo(dout);
        }

        dout.flush();

        try {
            worker.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return reader.vclocks;
    } finally {
        release(c);
    }
}

From source file:com.linkedin.pinot.core.startree.OffHeapStarTreeBuilder.java

/**
 * Assumes the file is already sorted, returns the unique combinations after removing a specified
 * dimension./*from w  w w .j  a va2  s.c  o  m*/
 * Aggregates the metrics for each unique combination, currently only sum is supported by default
 * @param startDocId
 * @param endDocId
 * @param file
 * @param splitDimensionId
 * @return
 * @throws Exception
 */
private Iterator<Pair<DimensionBuffer, MetricBuffer>> uniqueCombinations(int startDocId, int endDocId,
        File file, int splitDimensionId) throws Exception {
    StarTreeDataTable dataSorter = new StarTreeDataTable(file, dimensionSizeBytes, metricSizeBytes,
            getSortOrder());
    Iterator<Pair<byte[], byte[]>> iterator1 = dataSorter.iterator(startDocId, endDocId);
    File tempFile = new File(outDir, file.getName() + "_" + startDocId + "_" + endDocId + ".unique.tmp");
    DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)));
    while (iterator1.hasNext()) {
        Pair<byte[], byte[]> next = iterator1.next();
        byte[] dimensionBuffer = next.getLeft();
        byte[] metricBuffer = next.getRight();
        DimensionBuffer dimensions = DimensionBuffer.fromBytes(dimensionBuffer);
        for (int i = 0; i < numDimensions; i++) {
            String dimensionName = dimensionNameToIndexMap.inverse().get(i);
            if (i == splitDimensionId || (skipMaterializationForDimensions != null
                    && skipMaterializationForDimensions.contains(dimensionName))) {
                dos.writeInt(StarTreeIndexNodeInterf.ALL);
            } else {
                dos.writeInt(dimensions.getDimension(i));
            }
        }
        dos.write(metricBuffer);
    }
    dos.close();
    dataSorter = new StarTreeDataTable(tempFile, dimensionSizeBytes, metricSizeBytes, getSortOrder());
    dataSorter.sort(0, endDocId - startDocId);
    if (debugMode) {
        printFile(tempFile, 0, endDocId - startDocId);
    }
    final Iterator<Pair<byte[], byte[]>> iterator = dataSorter.iterator(0, endDocId - startDocId);
    return new Iterator<Pair<DimensionBuffer, MetricBuffer>>() {

        Pair<DimensionBuffer, MetricBuffer> prev = null;
        boolean done = false;

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean hasNext() {
            return !done;
        }

        @Override
        public Pair<DimensionBuffer, MetricBuffer> next() {
            while (iterator.hasNext()) {
                Pair<byte[], byte[]> next = iterator.next();
                byte[] dimBuffer = next.getLeft();
                byte[] metricBuffer = next.getRight();
                if (prev == null) {
                    prev = Pair.of(DimensionBuffer.fromBytes(dimBuffer),
                            MetricBuffer.fromBytes(metricBuffer, schema.getMetricFieldSpecs()));
                } else {
                    Pair<DimensionBuffer, MetricBuffer> current = Pair.of(DimensionBuffer.fromBytes(dimBuffer),
                            MetricBuffer.fromBytes(metricBuffer, schema.getMetricFieldSpecs()));
                    if (!current.getLeft().equals(prev.getLeft())) {
                        Pair<DimensionBuffer, MetricBuffer> ret = prev;
                        prev = current;
                        LOG.debug("Returning unique {}", prev.getLeft());
                        return ret;
                    } else {
                        prev.getRight().aggregate(current.getRight());
                    }
                }
            }
            done = true;
            LOG.debug("Returning unique {}", prev.getLeft());
            return prev;
        }
    };
}