Esempio n. 1
1
 public void setContent(byte[] cntnt) throws Exception {
   StringBuffer sb = new StringBuffer(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
   sb.append(OK_HDR);
   sb.append("Content-Type: ");
   sb.append(contentType);
   if (!isHTTP11 || !keepAlive || isMessages) {
     sb.append("\r\nConnection: close\r\nProxy-Connection: close");
   } else {
     sb.append("\r\nConnection: Keep-Alive\r\nProxy-Connection: Keep-Alive");
     sb.append("\r\nContent-Length: ");
     sb.append(cntnt.length);
   }
   sb.append("\r\n\r\n");
   sb.trimToSize();
   CharBuffer cb = CharBuffer.wrap(sb.toString());
   ByteBuffer tempBuffer;
   try {
     tempBuffer = Charset.forName("iso-8859-1").newEncoder().encode(cb);
   } catch (CharacterCodingException cce) {
     Server.debug(this, "prepareForSending: ", cce, Server.MSG_ERROR, Server.LVL_MINOR);
     try {
       tempBuffer = ByteBuffer.wrap(cb.toString().getBytes(Server.srv.DEFAULT_CHARSET));
     } catch (Exception e) {
       Server.debug(this, "prepareForSending: ", e, Server.MSG_ERROR, Server.LVL_MAJOR);
       throw e;
     }
   }
   this.buf = ByteBuffer.allocate(tempBuffer.capacity() + cntnt.length);
   this.buf.put(tempBuffer.array());
   this.buf.put(cntnt);
   this.buf.flip();
 }
Esempio n. 2
0
 /**
  * prepares the response for sending if a template is set, it will be rendered if no charbuffer is
  * present, even after rendering the template, there is nothing to send and prepareForSending will
  * just return
  */
 public void prepareForSending(CharBuffer cb) {
   if (cb == null || cb.length() < 1) return;
   try {
     buf = Charset.forName("iso-8859-1").newEncoder().encode(cb);
     return;
   } catch (CharacterCodingException cce) {
     Server.debug(this, "prepareForSending: ", cce, Server.MSG_ERROR, Server.LVL_MINOR);
   }
 }
Esempio n. 3
0
 public void prepareForSending(CharBuffer hdr, CharBuffer cntnt) {
   if (hdr == null || hdr.capacity() < 1) return;
   try {
     ByteBuffer hdrBytes = Charset.forName("iso-8859-1").newEncoder().encode(hdr);
     ByteBuffer cntntBytes =
         Charset.forName(Server.srv.DEFAULT_CHARSET).newEncoder().encode(cntnt);
     buf = ByteBuffer.allocate(hdrBytes.capacity() + cntntBytes.capacity());
     buf.put(hdrBytes);
     buf.put(cntntBytes);
     buf.flip();
   } catch (Exception e) {
     Server.debug(
         this,
         "Exception during prepareForSending(hdr/cntnt)",
         e,
         Server.MSG_ERROR,
         Server.LVL_MAJOR);
   }
 }