/*
(non-Javadoc)

@see
de.tud.ukp.kulessa.delta.data.codec.RevisionEncoderInterface#binaryDiff
(de.tud.ukp.kulessa.delta.data.codec.RevisionCodecData,
de.tud.ukp.kulessa.delta.data.tasks.content.Diff)
961331
@Override
	public byte[] binaryDiff(final RevisionCodecData codecData, final Diff diff)
		throws UnsupportedEncodingException, EncodingException
	{

		byte[] bData = encode(codecData, diff);
		if (MODE_ZIP_COMPRESSION) {

			Deflater compresser = new Deflater();
			compresser.setInput(bData);
			compresser.finish();

			byte[] output = new byte[1000];
			ByteArrayOutputStream stream = new ByteArrayOutputStream();

			int cLength;
			do {
				cLength = compresser.deflate(output);
				stream.write(output, 0, cLength);
			}
			while (cLength == 1000);

			output = stream.toByteArray();
			if (bData.length + 1 < output.length) {
				return bData;
			}
			else {

				stream = new ByteArrayOutputStream();
				stream.write(new byte[] { -128 }, 0, 1);
				stream.write(output, 0, output.length);

				return stream.toByteArray();
			}
		}

		return bData;
	}
1103611
public void writeDiff(final Task<Diff> diff, final int start)
		throws IOException
	{

		int size = diff.size();
		Diff d;
		String previousRevision = null, currentRevision = null;

		this.writer
				.write(WikipediaXMLKeys.KEY_START_PAGE.getKeyword() + "\r\n");

		ArticleInformation header = diff.getHeader();

		this.writer.write("\t" + WikipediaXMLKeys.KEY_START_TITLE.getKeyword());
		this.writer.write(header.getArticleName());
		this.writer.write(WikipediaXMLKeys.KEY_END_TITLE.getKeyword() + "\r\n");

		this.writer.write("\t" + WikipediaXMLKeys.KEY_START_ID.getKeyword());
		this.writer.write(Integer.toString(header.getArticleId()));
		this.writer.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

		this.writer.write("\t<partCounter>");
		this.writer.write(Integer.toString(diff.getPartCounter()));
		this.writer.write("</partCounter>\r\n");

		for (int i = start; i < size; i++) {
			d = diff.get(i);
			currentRevision = d.buildRevision(previousRevision);

			this.writer
					.write("\t"
							+ WikipediaXMLKeys.KEY_START_REVISION.getKeyword()
							+ "\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(d.getRevisionID()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

			this.writer.write("\t\t<revCount>");
			this.writer.write(Integer.toString(d.getRevisionCounter()));
			this.writer.write("</revCount>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TIMESTAMP.getKeyword());
			this.writer.write(d.getTimeStamp().toString());
			this.writer.write(WikipediaXMLKeys.KEY_END_TIMESTAMP.getKeyword()
					+ "\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TEXT.getKeyword());
			if (currentRevision != null) {
				this.writer.write(currentRevision);
				previousRevision = currentRevision;
			}
			this.writer.write(WikipediaXMLKeys.KEY_END_TEXT.getKeyword()
					+ "\r\n");

			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_END_REVISION.getKeyword() + "\r\n");

		}

		this.writer.write(WikipediaXMLKeys.KEY_END_PAGE.getKeyword() + "\r\n");
		this.writer.flush();
	}
1031096
protected void copyCodeFiles(File rootPackage, File outDir, Replacement replaceFn) throws IOException {
        if (rootPackage.isFile()) {
            copyFile(rootPackage, outDir, replaceFn);
        } else {
            outDir.mkdirs();
            String[] names = rootPackage.list();
            if (names != null) {
                for (String name: names) {
                    copyCodeFiles(new File(rootPackage, name), new File(outDir, name), replaceFn);
                }
            }
        }
    }
112730
def make_diff(current, revision):
    """"""
    the_diff = []
    dmp = diff_match_patch()

    for field in (set(current.field_dict.keys()) | set(revision.field_dict.keys())):
        # These exclusions really should be configurable
        if field == 'id' or field.endswith('_rendered'):
            continue
        # KeyError's may happen if the database structure changes
        # between the creation of revisions. This isn't ideal,
        # but should not be a fatal error.
        # Log this?
        missing_field = False
        try:
            cur_val = current.field_dict[field] or ""
        except KeyError:
            cur_val = "No such field in latest version\n"
            missing_field = True
        try:
            old_val = revision.field_dict[field] or ""
        except KeyError:
            old_val = "No such field in old version\n"
            missing_field = True
        if missing_field:
            # Ensure that the complete texts are marked as changed
            # so new entries containing any of the marker words
            # don't show up as differences
            diffs = [(dmp.DIFF_DELETE, old_val), (dmp.DIFF_INSERT, cur_val)]
            patch =  dmp.diff_prettyHtml(diffs)
        elif isinstance(cur_val, Markup):
            # we roll our own diff here, so we can compare of the raw
            # markdown, rather than the rendered result.
            if cur_val.raw == old_val.raw:
                continue
            diffs = dmp.diff_main(old_val.raw, cur_val.raw)
            patch =  dmp.diff_prettyHtml(diffs)
        elif cur_val == old_val:
            continue
        else:
            # Compare the actual field values
            diffs = dmp.diff_main(force_text(old_val), force_text(cur_val))
            patch = dmp.diff_prettyHtml(diffs)
        the_diff.append((field, patch))

    the_diff.sort()
    return the_diff
286278
private javax.jcr.Binary getBinaryContent() {
        try {
            return getProperty(JCR_DATA).getBinary();
        } catch (final PathNotFoundException e) {
            throw new PathNotFoundRuntimeException(e);
        } catch (final RepositoryException e) {
            throw new RepositoryRuntimeException(e);
        }
    }
749808
public void writeDiffFile(final Task<Diff> diff)
		throws IOException
	{

		int partsCount;
		int size = diff.size();
		Diff d;
		DiffPart p;
		RevisionCodecData codec;

		this.writer
				.write(WikipediaXMLKeys.KEY_START_PAGE.getKeyword() + "\r\n");

		ArticleInformation header = diff.getHeader();

		this.writer.write("\t" + WikipediaXMLKeys.KEY_START_TITLE.getKeyword());
		this.writer.write(header.getArticleName());
		this.writer.write(WikipediaXMLKeys.KEY_END_TITLE.getKeyword() + "\r\n");

		this.writer.write("\t" + WikipediaXMLKeys.KEY_START_ID.getKeyword());
		this.writer.write(Integer.toString(header.getArticleId()));
		this.writer.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

		this.writer.write("\t<partCounter>");
		this.writer.write(Integer.toString(diff.getPartCounter()));
		this.writer.write("</partCounter>\r\n");

		for (int i = 0; i < size; i++) {
			d = diff.get(i);

			this.writer
					.write("\t"
							+ WikipediaXMLKeys.KEY_START_REVISION.getKeyword()
							+ "\r\n");

			codec = d.getCodecData();
			if (!codec.isConverted()) {
				codec.totalSizeInBits();
			}

			this.writer.write("\t\t<codecData>\r\n");

			this.writer.write("\t\t\t<s>"
					+ Integer.toString(codec.getBlocksizeS()) + "</s>\r\n");
			this.writer.write("\t\t\t<e>"
					+ Integer.toString(codec.getBlocksizeE()) + "</e>\r\n");
			this.writer.write("\t\t\t<b>"
					+ Integer.toString(codec.getBlocksizeB()) + "</b>\r\n");
			this.writer.write("\t\t\t<l>"
					+ Integer.toString(codec.getBlocksizeL()) + "</l>\r\n");

			this.writer.write("\t\t</codecData>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(d.getRevisionID()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

			this.writer.write("\t\t<revCount>");
			this.writer.write(Integer.toString(d.getRevisionCounter()));
			this.writer.write("</revCount>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TIMESTAMP.getKeyword());
			this.writer.write(d.getTimeStamp().toString());
			this.writer.write(WikipediaXMLKeys.KEY_END_TIMESTAMP.getKeyword()
					+ "\r\n");

			this.writer.write("\t\t<diff>\r\n");
			partsCount = d.size();
			for (int j = 0; j < partsCount; j++) {

				p = d.get(j);
				this.writer.write("\t\t\t<diffPart>\r\n");

				this.writer.write("\t\t\t\t<action>" + p.getAction()
						+ "</action>\r\n");
				this.writer.write("\t\t\t\t<start>"
						+ Integer.toString(p.getStart()) + "</start>\r\n");
				this.writer.write("\t\t\t\t<end>"
						+ Integer.toString(p.getEnd()) + "</end>\r\n");
				if (p.getText() != null) {
					this.writer
							.write("\t\t\t\t<content xml:space=\"preserve\">"
									+ p.getText());
					this.writer.write("</content>\r\n");
				}

				this.writer.write("\t\t\t</diffPart>\r\n");
			}

			this.writer.write("\t\t</diff>\r\n");
			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_END_REVISION.getKeyword() + "\r\n");
		}

		this.writer.write(WikipediaXMLKeys.KEY_END_PAGE.getKeyword() + "\r\n");
		this.writer.flush();
	}
179752
@Override
	public String encodeDiff(final RevisionCodecData codecData, final Diff diff)
		throws UnsupportedEncodingException, EncodingException
	{

		String sEncoding;
		byte[] bData = encode(codecData, diff);
		if (MODE_ZIP_COMPRESSION) {

			Deflater compresser = new Deflater();
			compresser.setInput(bData);
			compresser.finish();

			byte[] output = new byte[1000];
			ByteArrayOutputStream stream = new ByteArrayOutputStream();

			int cLength;
			do {
				cLength = compresser.deflate(output);
				stream.write(output, 0, cLength);
			}
			while (cLength == 1000);

			output = stream.toByteArray();

			if (bData.length + 1 < output.length) {
				sEncoding = Base64.encodeBase64String(bData);
			}
			else {
				sEncoding = "_" + Base64.encodeBase64String(output);
			}
		}
		else {
			sEncoding = Base64.encodeBase64String(bData);
		}

		return sEncoding;
	}
1095114
def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True):
    

    for filenode in (filenode_old, filenode_new):
        if not isinstance(filenode, FileNode):
            raise VCSError("Given object should be FileNode object, not %s"
                % filenode.__class__)

    old_raw_id = getattr(filenode_old.changeset, 'raw_id', '0' * 40)
    new_raw_id = getattr(filenode_new.changeset, 'raw_id', '0' * 40)

    repo = filenode_new.changeset.repository
    vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path,
                                 ignore_whitespace)

    return vcs_gitdiff
598843
@Override
    public boolean parseBinaryFirstLine(WsByteBuffer buff) throws MalformedMessageException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "parseBinaryFirstLine for " + this);
            Tr.debug(tc, "Buffer: " + buff);
        }
        // check the version first if we need to
        if (getBinaryParseState() == HttpInternalConstants.PARSING_BINARY_VERSION) {
            if (!buff.hasRemaining()) {
                return false;
            }
            byte version = buff.get();
            if (version != HttpInternalConstants.BINARY_TRANSPORT_V1) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Unsupported binary version in message: " + version);
                }
                throw new MalformedMessageException("Invalid binary message");
            }
            setBinaryParseState(HttpInternalConstants.PARSING_VERSION_ID_OR_LEN);
            resetCacheToken(4);
        }

        // stop parsing the FirstLine when we have parsed the status or the
        // reason header or we hit the end of the buffer and need to read more
        boolean lineEnds = false;
        int value;
        while (!lineEnds) {
            // at this point, the parsed token array is always set up, so we
            // can try to fill it now
            if (!fillCacheToken(buff)) {
                return false;
            }
            switch (getBinaryParseState()) {
                case HttpInternalConstants.PARSING_VERSION_ID_OR_LEN:
                    value = GenericUtils.asInt(getParsedToken());
                    if (0 == (value & GenericConstants.KNOWN_MASK)) {
                        // known version ordinal
                        setVersion(VersionValues.getByOrdinal(value));
                        setBinaryParseState(HttpInternalConstants.PARSING_STATUS);
                        resetCacheToken(4);
                    } else {
                        // unknown version length
                        setBinaryParseState(HttpInternalConstants.PARSING_UNKNOWN_VERSION);
                        resetCacheToken(value & GenericConstants.UNKNOWN_MASK);
                    }
                    break;

                case HttpInternalConstants.PARSING_UNKNOWN_VERSION:
                    setVersion(VersionValues.find(getParsedToken()));
                    setBinaryParseState(HttpInternalConstants.PARSING_STATUS);
                    createCacheToken(4);
                    break;

                case HttpInternalConstants.PARSING_STATUS:
                    setStatusCode(GenericUtils.asInt(getParsedToken()));
                    setBinaryParseState(HttpInternalConstants.PARSING_REASON_LEN);
                    resetCacheToken(4);
                    break;

                case HttpInternalConstants.PARSING_REASON_LEN:
                    value = GenericUtils.asInt(getParsedToken());
                    if (0 == value) {
                        // end of first line response headers
                        setBinaryParseState(GenericConstants.PARSING_HDR_FLAG);
                        resetCacheToken(4);
                        lineEnds = true;
                    } else {
                        setBinaryParseState(HttpInternalConstants.PARSING_REASON);
                        resetCacheToken(value);
                    }
                    break;

                case HttpInternalConstants.PARSING_REASON:
                    setReasonPhrase(getParsedToken());
                    setBinaryParseState(GenericConstants.PARSING_HDR_FLAG);
                    createCacheToken(4);
                    lineEnds = true;
                    break;

                default:
                    throw new MalformedMessageException("Invalid state in line: " + getBinaryParseState());
            } // end of switch

        } // end of while loop

        setFirstLineComplete(true);
        return true;
    }
1044927
private void marshallBinaryPayload(Object val) {
        if (val instanceof ByteBuffer) {
            request.setContent(BinaryUtils.toStream((ByteBuffer) val));
        } else if (val instanceof InputStream) {
            request.setContent((InputStream) val);
        }
    }
1261616
public static <K, V> Map<K, V> updateMap(final Map<K, V> original, MapDifference<K, V> diff) throws MergeException {
        Map<K, V> result = new HashMap<K, V>(original);
        if (diff.areEqual()) {
            return result;
        }
        for (Entry<K, V> entry : diff.entriesOnlyOnLeft().entrySet()) {
            V originalValue = original.get(entry.getKey());
            if (ObjectUtils.equals(originalValue, entry.getValue())) {
                result.remove(entry.getKey());
            }
        }
        for (Entry<K, V> entry : diff.entriesOnlyOnRight().entrySet()) {
            K key = entry.getKey();
            if (original.containsKey(key)) {
                if (ObjectUtils.notEqual(original.get(key), entry.getValue())) {
                    throw new MergeException(String.format(
                        "tried to introduce a new value, but it was already there: %s (%s,%s)",
                        key, original.get(key), entry.getValue()));
                }
            }
            result.put(entry.getKey(), entry.getValue());
        }
        for (Entry<K, ValueDifference<V>> entry : diff.entriesDiffering().entrySet()) {
            K key = entry.getKey();
            V originalValue = original.get(entry.getKey());
            if (ObjectUtils.equals(originalValue, entry.getValue().leftValue())) {
                // Map changed in diff only
                result.put(key, entry.getValue().rightValue());
            } else if (ObjectUtils.equals(originalValue, entry.getValue().rightValue())) {
                // Diff would change value to value already in original Map
                result.put(key, originalValue);
            } else {
                // Merge conflict, got 3 different Values
                String errorMessage =
                    String
                        .format(
                            "Changes could not be applied, because original value differes from left-side of the"
                                    + "MapDifference: %s (%s,%s)", entry.getKey(), original.get(entry.getKey()),
                            entry.getValue());
                throw new MergeException(errorMessage);
            }
        }
        return result;
    }
1288101
@NullableDecl
  final String safeFormatDiff(
      @NullableDecl A actual, @NullableDecl E expected, ExceptionStore exceptions) {
    try {
      return formatDiff(actual, expected);
    } catch (RuntimeException e) {
      exceptions.addFormatDiffException(Correspondence.class, e, actual, expected);
      return null;
    }
  }
1241661
public void updateBinaryRuleExpectations(double[] binaryRuleMarginal) {
    for (int i = 0; i < binaryRuleExpectations.length; i++) {
      binaryRuleExpectations[i] += binaryRuleMarginal[i];
    }
  }
1232669
@Override
    public boolean parseBinaryFirstLine(WsByteBuffer buff) throws MalformedMessageException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "parseBinaryFirstLine for " + this);
            Tr.debug(tc, "Buffer: " + buff);
        }
        if (getBinaryParseState() == HttpInternalConstants.PARSING_BINARY_VERSION) {
            if (!buff.hasRemaining()) {
                return false;
            }
            byte version = buff.get();
            if (version != HttpInternalConstants.BINARY_TRANSPORT_V1) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Unsupported binary version in message: " + version);
                }
                throw new MalformedMessageException("Invalid binary message");
            }
            setBinaryParseState(HttpInternalConstants.PARSING_METHOD_ID_OR_LEN);
            resetCacheToken(4);
        }

        boolean complete = false;
        int value;
        while (!complete) {
            // at this point, the parsed token array is always set up, so we
            // can try to fill it now
            if (!fillCacheToken(buff)) {
                return false;
            }
            switch (getBinaryParseState()) {
                case HttpInternalConstants.PARSING_METHOD_ID_OR_LEN:
                    value = GenericUtils.asInt(getParsedToken());
                    if (0 == (value & GenericConstants.KNOWN_MASK)) {
                        setMethod(MethodValues.getByOrdinal(value));
                        setBinaryParseState(HttpInternalConstants.PARSING_URI_LEN);
                        resetCacheToken(4);
                    } else {
                        setBinaryParseState(HttpInternalConstants.PARSING_UNKNOWN_METHOD);
                        resetCacheToken(value & GenericConstants.UNKNOWN_MASK);
                    }
                    break;
                case HttpInternalConstants.PARSING_UNKNOWN_METHOD:
                    setMethod(MethodValues.find(getParsedToken()));
                    setBinaryParseState(HttpInternalConstants.PARSING_URI_LEN);
                    createCacheToken(4);
                    break;

                case HttpInternalConstants.PARSING_URI_LEN:
                    setBinaryParseState(HttpInternalConstants.PARSING_URI);
                    resetCacheToken(GenericUtils.asInt(getParsedToken()));
                    break;

                case HttpInternalConstants.PARSING_URI:
                    setRequestURL(getParsedToken());
                    setBinaryParseState(HttpInternalConstants.PARSING_VERSION_ID_OR_LEN);
                    createCacheToken(4);
                    break;

                case HttpInternalConstants.PARSING_VERSION_ID_OR_LEN:
                    value = GenericUtils.asInt(getParsedToken());
                    if (0 == (value & GenericConstants.KNOWN_MASK)) {
                        setVersion(VersionValues.getByOrdinal(value));
                        setBinaryParseState(GenericConstants.PARSING_HDR_FLAG);
                        resetCacheToken(4);
                        complete = true;
                    } else {
                        setBinaryParseState(HttpInternalConstants.PARSING_UNKNOWN_VERSION);
                        resetCacheToken(value & GenericConstants.UNKNOWN_MASK);
                    }
                    break;

                case HttpInternalConstants.PARSING_UNKNOWN_VERSION:
                    setVersion(VersionValues.find(getParsedToken()));
                    setBinaryParseState(GenericConstants.PARSING_HDR_FLAG);
                    createCacheToken(4);
                    complete = true;
                    break;

                default:
                    throw new MalformedMessageException("Invalid state in first line: " + getBinaryParseState());
            } // end of switch block

        } // end of while loop

        setFirstLineComplete(true);
        return true;
    }
546060
private static final int writeDiff(int diff, byte buffer[], int offset) 
    {
        if (diff >= SLOPE_REACH_NEG_1_) {
            if (diff <= SLOPE_REACH_POS_1_) {
                buffer[offset ++] = (byte)(SLOPE_MIDDLE_ + diff);
            } 
            else if (diff <= SLOPE_REACH_POS_2_) {
                buffer[offset ++] = (byte)(SLOPE_START_POS_2_ 
                                           + (diff / SLOPE_TAIL_COUNT_));
                buffer[offset ++] = (byte)(SLOPE_MIN_ + 
                                           (diff % SLOPE_TAIL_COUNT_));
            } 
            else if (diff <= SLOPE_REACH_POS_3_) {
                buffer[offset + 2] = (byte)(SLOPE_MIN_ 
                                            + (diff % SLOPE_TAIL_COUNT_));
                diff /= SLOPE_TAIL_COUNT_;
                buffer[offset + 1] = (byte)(SLOPE_MIN_ 
                                            + (diff % SLOPE_TAIL_COUNT_));
                buffer[offset] = (byte)(SLOPE_START_POS_3_ 
                                        + (diff / SLOPE_TAIL_COUNT_));
                offset += 3;
            } 
            else {
                buffer[offset + 3] = (byte)(SLOPE_MIN_ 
                                            + diff % SLOPE_TAIL_COUNT_);
                diff /= SLOPE_TAIL_COUNT_;
                buffer[offset + 2] = (byte)(SLOPE_MIN_ 
                                        + diff % SLOPE_TAIL_COUNT_);
                diff /= SLOPE_TAIL_COUNT_;
                buffer[offset + 1] = (byte)(SLOPE_MIN_ 
                                            + diff % SLOPE_TAIL_COUNT_);
                buffer[offset] = (byte)SLOPE_MAX_;
                offset += 4;
            }
        } 
        else {
            long division = getNegDivMod(diff, SLOPE_TAIL_COUNT_);
            int modulo = (int)division;
            if (diff >= SLOPE_REACH_NEG_2_) {
                diff = (int)(division >> 32);
                buffer[offset ++] = (byte)(SLOPE_START_NEG_2_ + diff);
                buffer[offset ++] = (byte)(SLOPE_MIN_ + modulo);
            } 
            else if (diff >= SLOPE_REACH_NEG_3_) {
                buffer[offset + 2] = (byte)(SLOPE_MIN_ + modulo);
                diff = (int)(division >> 32);
                division = getNegDivMod(diff, SLOPE_TAIL_COUNT_);
                modulo = (int)division;
                diff = (int)(division >> 32);
                buffer[offset + 1] = (byte)(SLOPE_MIN_ + modulo);
                buffer[offset] = (byte)(SLOPE_START_NEG_3_ + diff);
                offset += 3;
            } 
            else {
                buffer[offset + 3] = (byte)(SLOPE_MIN_ + modulo);
                diff = (int)(division >> 32);
                division = getNegDivMod(diff, SLOPE_TAIL_COUNT_);
                modulo = (int)division;
                diff = (int)(division >> 32);
                buffer[offset + 2] = (byte)(SLOPE_MIN_ + modulo);
                division = getNegDivMod(diff, SLOPE_TAIL_COUNT_);
                modulo = (int)division;
                buffer[offset + 1] = (byte)(SLOPE_MIN_ + modulo);
                buffer[offset] = SLOPE_MIN_;
                offset += 4;
            }
        }
        return offset;
    }
13151
private void verify(final Task<Diff> task, final Diff decodedDiff,
			final Diff originalDiff)
		throws SQLConsumerException
	{

		String orig = originalDiff.toString();
		String deco = decodedDiff.toString();

		boolean notEqual = !orig.equals(deco);

		if (notEqual && MODE_SURROGATES == SurrogateModes.REPLACE) {

			char[] origDiff = orig.toCharArray();

			// TODO: test
			if (Surrogates.scan(origDiff)) {

				String repDiff = new String(Surrogates.replace(origDiff));
				notEqual = !repDiff.equals(deco);
			}
		}

		if (notEqual) {

			if (MODE_DEBUG_OUTPUT_ACTIVATED) {

				try {
					// System.out.println("DEBUG\t" + task.toString());

					WikipediaXMLWriter writer = new WikipediaXMLWriter(
							LOGGING_PATH_DIFFTOOL + LOGGING_PATH_DEBUG
									+ task.getHeader().getArticleName()
									+ ".dbg");

					switch (task.getTaskType()) {
					case TASK_FULL:
					case TASK_PARTIAL_FIRST:
						writer.writeDiff(task);
						break;

					case TASK_PARTIAL:
					case TASK_PARTIAL_LAST: {

						int revCount = originalDiff.getRevisionCounter();
						Diff d;
						boolean fullRev = false;

						for (int diffCount = 0; !fullRev
								&& diffCount < originalDiff.size(); diffCount++) {

							d = task.get(diffCount);
							if (d.getRevisionCounter() <= revCount
									&& d.isFullRevision()) {
								fullRev = true;
								writer.writeDiff(task, diffCount);
							}
						}

						if (!fullRev) {
							writer.writeDiffFile(task);
						}

					}
						break;
					default:
						throw new IOException("Unknown TaskType");
						// TODO: Debug output
					}

					writer.close();
				}
				catch (IOException e) {
					ConsumerLogMessages.logException(logger, e);
				}
			}

			throw ErrorFactory
					.createSQLConsumerException(
							ErrorKeys.DIFFTOOL_SQLCONSUMER_ENCODING_VERIFICATION_FAILED,
							"Redecoding of "
									+ task.getHeader().getArticleName()
									+ " failed at revision "
									+ originalDiff.getRevisionCounter() + ".");
		}
	}
1154413
private static ByteBuf contentFromWriteRequest(BinaryRequest request) {
        ByteBuf content = null;
        if (request instanceof BinaryStoreRequest) {
            content = ((BinaryStoreRequest) request).content();
        } else if (request instanceof AppendRequest) {
            content = ((AppendRequest) request).content();
        } else if (request instanceof PrependRequest) {
            content = ((PrependRequest) request).content();
        } else if (request instanceof BinarySubdocRequest) {
            content = ((BinarySubdocRequest) request).content();
        } else if (request instanceof BinarySubdocMultiLookupRequest) {
            content = ((BinarySubdocMultiLookupRequest) request).content();
        } else if (request instanceof BinarySubdocMultiMutationRequest) {
            content = ((BinarySubdocMultiMutationRequest) request).content();
        }
        return content;
    }