Example usage for org.apache.http.util EncodingUtils getAsciiString

List of usage examples for org.apache.http.util EncodingUtils getAsciiString

Introduction

In this page you can find the example usage for org.apache.http.util EncodingUtils getAsciiString.

Prototype

public static String getAsciiString(byte[] bArr, int i, int i2) 

Source Link

Usage

From source file:de.tlabs.ssr.g1.client.XMLChunkInputStream.java

public boolean bufferNextChunk() throws IOException {
    boolean readDelimiter = false;

    arrayBuffer.clear();/*w  w  w  .  ja  va 2 s .c om*/

    // read input data until delimiter is encountered
    while (!readDelimiter) {
        // process data which is still in temp buffer
        if (tempBufferEnd - tempBufferStart != 0) {
            // find next '\0'
            for (int i = tempBufferStart; i < tempBufferEnd; i++) {
                if (tempBuffer[i] == '\0') {
                    // copy chunk to arrayBuffer
                    arrayBuffer.append(tempBuffer, tempBufferStart, i - tempBufferStart);

                    // update tempBufferStart (and skip '\0')
                    tempBufferStart = i + 1;

                    // break loop
                    readDelimiter = true;
                    break;
                }
            }

            // was delimiter read?
            if (!readDelimiter) {
                // copy whole temp buffer to array buffer
                arrayBuffer.append(tempBuffer, tempBufferStart, tempBufferEnd - tempBufferStart);
                tempBufferStart = 0;
                tempBufferEnd = 0;
            }
        }

        // was delimiter read out of temp buffer?
        if (!readDelimiter) {
            // temp buffer is definitely empty now and delimiter was not read yet
            // so fill buffer again
            if (fillTempBuffer() == -1)
                return false;
        }
    }

    // set properties of this ByteArrayInputStream
    this.mark = 0;
    this.pos = 0;
    this.buf = arrayBuffer.buffer();
    this.count = arrayBuffer.length();

    // print to log
    if (printToLog) {
        for (int i = 0; i < count; i += 100) {
            Log.d(TAG, EncodingUtils.getAsciiString(buf, i, Math.min(100, count - i)));
        }
    }

    return true;
}

From source file:com.lib.DstabiProvider.java

/**
 * ziskani stavoveho kodu ze zpravy/*from w  ww  . ja  v  a  2 s . co m*/
 * 
 * @param msg
 * @return
 */
private String parseMessagegetCode(byte[] msg) {
    if (msg.length == 1) {// prisel jednoduchy vystup K nebo E
        return EncodingUtils.getAsciiString(msg, 0, 1);
    } else if (msg.length > 1) {

        String code = EncodingUtils.getAsciiString(msg, 0, 1);

        if (code.equals(OK) || code.equals(ERROR)) { // prisel zacatek profilu odstranime K na zacatku profilu
            return code;
        }
    }

    return new String();
}

From source file:com.lib.DstabiProvider.java

/**
 * ziskani dat ze zpravy/*from w w w . jav a 2 s .com*/
 * 
 * @param msg
 * @return
 */
private byte[] parseMessagegetData(byte[] msg) {
    //zprava je 
    if (msg.length == 1 && protocolState != PROTOCOL_STATE_WAIT_FOR_ALL_DATA) {// prisel jednoduchy vystup K nebo E
        return null;
    } else if (msg.length > 1) {

        String code = EncodingUtils.getAsciiString(msg, 0, 1);
        Log.d(TAG, code);
        if ((code.equals(OK) || code.equals(ERROR)) && protocolState != PROTOCOL_STATE_WAIT_FOR_ALL_DATA) { // prisel zacatek profilu odstranime K na zacatku profilu a nasmime byt v modu cekani na data

            byte[] result = new byte[msg.length - 1];
            System.arraycopy(msg, 1, result, 0, msg.length - 1);
            return result;
        }
    }

    return msg;
}