public static Response newFixedLengthResponse(IStatus status, String mimeType, String txt) {
        ContentType contentType = new ContentType(mimeType);
        if (txt == null) {
            return newFixedLengthResponse(status, mimeType, new ByteArrayInputStream(new byte[0]), 0);
        } else {
            byte[] bytes;
            try {
                CharsetEncoder newEncoder = Charset.forName(contentType.getEncoding()).newEncoder();
                if (!newEncoder.canEncode(txt)) {
                    contentType = contentType.tryUTF8();
                }
                bytes = txt.getBytes(contentType.getEncoding());
            } catch (UnsupportedEncodingException e) {
                NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
                bytes = new byte[0];
            }
            return newFixedLengthResponse(status, contentType.getContentTypeHeader(), new ByteArrayInputStream(bytes), bytes.length);
        }
    }
public static Response newFixedLengthResponse(IStatus status, String mimeType, String txt) {
        ContentType contentType = new ContentType(mimeType);
        if (txt == null) {
            return newFixedLengthResponse(status, mimeType, new ByteArrayInputStream(new byte[0]), 0);
        } else {
            byte[] bytes;
            try {
                CharsetEncoder newEncoder = Charset.forName(contentType.getEncoding()).newEncoder();
                if (!newEncoder.canEncode(txt)) {
                    contentType = contentType.tryUTF8();
                }
                bytes = txt.getBytes(contentType.getEncoding());
            } catch (UnsupportedEncodingException e) {
                NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
                bytes = new byte[0];
            }
            return newFixedLengthResponse(status, contentType.getContentTypeHeader(), new ByteArrayInputStream(bytes), bytes.length);
        }
    }
public static Response newFixedLengthResponse ( IStatus status , String mimeType , String txt ) { ContentType contentType = new ContentType ( mimeType ) ; if ( txt == null ) { return newFixedLengthResponse ( status , mimeType , new ByteArrayInputStream ( new byte [ 0 ] ) , 0 ) ; } else { byte [ ] bytes ; try { CharsetEncoder newEncoder = Charset . forName ( contentType . getEncoding ( ) ) . newEncoder ( ) ; if ( ! newEncoder . canEncode ( txt ) ) { contentType = contentType . tryUTF8 ( ) ; } bytes = txt . getBytes ( contentType . getEncoding ( ) ) ; } catch ( UnsupportedEncodingException e ) { NanoHTTPD . LOG . log ( Level . SEVERE , "encoding problem, responding nothing" , e ) ; bytes = new byte [ 0 ] ; } return newFixedLengthResponse ( status , contentType . getContentTypeHeader ( ) , new ByteArrayInputStream ( bytes ) , bytes . length ) ; } }
Create a text response with known length.
Create a text response with known length .