/**
  * Utility function to add a new decoded data
  *
  * @param data
  */
 private void addHttpData(InterfaceHttpData data) {
   if (data == null) {
     return;
   }
   List<InterfaceHttpData> datas = bodyMapHttpData.get(data.getName());
   if (datas == null) {
     datas = new ArrayList<InterfaceHttpData>(1);
     bodyMapHttpData.put(data.getName(), datas);
   }
   datas.add(data);
   bodyListHttpData.add(data);
 }
Example #2
0
 public int compareTo(InterfaceHttpData arg0) {
   if (!(arg0 instanceof Attribute)) {
     throw new ClassCastException(
         "Cannot compare " + getHttpDataType() + " with " + arg0.getHttpDataType());
   }
   return compareTo((Attribute) arg0);
 }
Example #3
0
 @Override
 public int compareTo(InterfaceHttpData o) {
   if (!(o instanceof FileUpload)) {
     throw new ClassCastException(
         "Cannot compare " + getHttpDataType() + " with " + o.getHttpDataType());
   }
   return compareTo((FileUpload) o);
 }
 /**
  * From the current context (currentBuffer and currentData), returns the next HttpChunk (if
  * possible) trying to get sizeleft bytes more into the currentBuffer. This is the UrlEncoded
  * version.
  *
  * @param sizeleft the number of bytes to try to get from currentData
  * @return the next HttpChunk or null if not enough bytes were found
  * @throws ErrorDataEncoderException if the encoding is in error
  */
 private HttpChunk encodeNextChunkUrlEncoded(int sizeleft) throws ErrorDataEncoderException {
   if (currentData == null) {
     return null;
   }
   int size = sizeleft;
   ChannelBuffer buffer;
   if (isKey) {
     // get name
     String key = currentData.getName();
     buffer = ChannelBuffers.wrappedBuffer(key.getBytes());
     isKey = false;
     if (currentBuffer == null) {
       currentBuffer =
           ChannelBuffers.wrappedBuffer(buffer, ChannelBuffers.wrappedBuffer("=".getBytes()));
       // continue
       size -= buffer.readableBytes() + 1;
     } else {
       currentBuffer =
           ChannelBuffers.wrappedBuffer(
               currentBuffer, buffer, ChannelBuffers.wrappedBuffer("=".getBytes()));
       // continue
       size -= buffer.readableBytes() + 1;
     }
     if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) {
       buffer = fillChannelBuffer();
       return new DefaultHttpChunk(buffer);
     }
   }
   try {
     buffer = ((Attribute) currentData).getChunk(size);
   } catch (IOException e) {
     throw new ErrorDataEncoderException(e);
   }
   ChannelBuffer delimiter = null;
   if (buffer.readableBytes() < size) {
     // delimiter
     isKey = true;
     delimiter = iterator.hasNext() ? ChannelBuffers.wrappedBuffer("&".getBytes()) : null;
   }
   if (buffer.capacity() == 0) {
     // end for current InterfaceHttpData, need potentially more data
     currentData = null;
     if (currentBuffer == null) {
       currentBuffer = delimiter;
     } else {
       if (delimiter != null) {
         currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer, delimiter);
       }
     }
     if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) {
       buffer = fillChannelBuffer();
       return new DefaultHttpChunk(buffer);
     }
     return null;
   }
   if (currentBuffer == null) {
     if (delimiter != null) {
       currentBuffer = ChannelBuffers.wrappedBuffer(buffer, delimiter);
     } else {
       currentBuffer = buffer;
     }
   } else {
     if (delimiter != null) {
       currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer, buffer, delimiter);
     } else {
       currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer, buffer);
     }
   }
   if (currentBuffer.readableBytes() < HttpPostBodyUtil.chunkSize) {
     // end for current InterfaceHttpData, need more data
     currentData = null;
     isKey = true;
     return null;
   }
   buffer = fillChannelBuffer();
   // size = 0
   return new DefaultHttpChunk(buffer);
 }