private void writeEncoded(char[] ca,int offset, int length) throws IOException { if (_bout==null) { _bout = new ByteArrayOutputStream2(2*length); _writer = new OutputStreamWriter(_bout,StringUtil.__ISO_8859_1); } else _bout.reset(); _writer.write(ca,offset,length); _writer.flush(); ensureSpareCapacity(_bout.getCount()); System.arraycopy(_bout.getBuf(),0,_buf,_size,_bout.getCount()); _size+=_bout.getCount(); }
ByteArrayOutputStream2 output = new ByteArrayOutputStream2(); size=output.size(); value = size==0?"":output.toString(charset); output.setCount(0); if (key != null) output.write(c); break; size=output.size(); key = size==0?"":output.toString(charset); output.setCount(0); break; case '+': output.write(' '); break; case '%': output.write((digit<<4) + TypeUtil.convertHexDigit((byte)c)); digits=0; output.write(c); break; size=output.size(); if (key != null) value = size==0?"":output.toString(charset);
out._bytes.reset(); int chars = length>MAX_OUTPUT_CHARS?MAX_OUTPUT_CHARS:length; byte[] buffer=out._bytes.getBuf(); int bytes=out._bytes.getCount(); out._bytes.setCount(bytes); byte[] buffer=out._bytes.getBuf(); int bytes=out._bytes.getCount(); out._bytes.setCount(bytes); break; out._bytes.writeTo(out); length-=chars; offset+=chars;
public void content(Buffer ref) throws IOException { if (_parsedContent==null) _parsedContent=new ByteArrayOutputStream2(); _parsedContent.write(ref.asArray()); } }
public void setCharacterEncoding(String encoding) { if (encoding == null || StringUtil.__ISO_8859_1.equalsIgnoreCase(encoding)) { _writeMode = WRITE_ISO1; } else if (StringUtil.__UTF8.equalsIgnoreCase(encoding)) { _writeMode = WRITE_UTF8; } else { _writeMode = WRITE_CONV; if (_out._characterEncoding == null || !_out._characterEncoding.equalsIgnoreCase(encoding)) _out._converter = null; // Set lazily in getConverter() } _out._characterEncoding = encoding; if (_out._bytes==null) _out._bytes = new ByteArrayOutputStream2(MAX_OUTPUT_CHARS); }
public void reset(int minSize) { reset(); if (buf.length<minSize) { buf=new byte[minSize]; } }
public String getContent() { if (_parsedContent!=null) return _parsedContent.toString(); if (_genContent!=null) return new String(_genContent); return null; }
public String generate() throws IOException { Buffer bb=new ByteArrayBuffer(32*1024 + (_genContent!=null?_genContent.length:0)); Buffer sb=new ByteArrayBuffer(4*1024); StringEndPoint endp = new StringEndPoint(); HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); if (_method!=null) { generator.setRequest(getMethod(),getURI()); if (_version==null) generator.setVersion(HttpVersions.HTTP_1_1_ORDINAL); else generator.setVersion(HttpVersions.CACHE.getOrdinal(HttpVersions.CACHE.lookup(_version))); generator.completeHeader(_fields,false); if (_genContent!=null) generator.addContent(new View(new ByteArrayBuffer(_genContent)),false); else if (_parsedContent!=null) generator.addContent(new ByteArrayBuffer(_parsedContent.toByteArray()),false); } generator.complete(); generator.flush(); return endp.getOutput(); }