Example usage for java.io Writer append

List of usage examples for java.io Writer append

Introduction

In this page you can find the example usage for java.io Writer append.

Prototype

public Writer append(CharSequence csq, int start, int end) throws IOException 

Source Link

Document

Appends a subsequence of the specified character sequence to this writer.

Usage

From source file:org.apache.stanbol.enhancer.nlp.utils.NIFHelper.java

/**
 * Creates the UTF8 byte representation for the '{prefix}({selected}){suffix}'
 * calculated based on the parsed parameters
 * @param text the text/*  w  w w  .  j  a v a 2s .c  o  m*/
 * @param contextStart the start index of the prefix
 * @param start the start index of the selected text part
 * @param end the end index of the selecte text part
 * @param contextEnd the end index of the suffix
 * @return the HASH string representation of the MD5 over 
 *  <code>'{prefix}({selected}){suffix}'</code> (NOTE the brackets that are
 *  added at the start/end of the selected text)
 */
private static String getContextDigest(String text, int contextStart, int start, int end, int contextEnd) {
    ByteArrayOutputStream contextOs = new ByteArrayOutputStream();
    Writer contextWriter = new OutputStreamWriter(contextOs, UTF8);
    try {
        if (contextStart < start) {
            contextWriter.append(text, contextStart, start);
        }
        contextWriter.append('(');
        if (start < end) {
            contextWriter.append(text, start, end);
        }
        contextWriter.append(')');
        if (end < contextEnd) {
            contextWriter.append(text, end, contextEnd);
        }
        contextWriter.flush();
        return ContentItemHelper.streamDigest(new ByteArrayInputStream(contextOs.toByteArray()), null, "MD5");
    } catch (IOException e) {
        //NO IOExceptions in in-memory stream implementations
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(contextOs);
    }
}