Package jodd.io

Examples of jodd.io.FastByteArrayOutputStream


          }
        }
        putFile(header.formFieldName, newFile);
      } else {
        // no file, therefore it is regular form parameter.
        FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
        input.copyAll(fbos);
        String value = encoding != null ? new String(fbos.toByteArray(), encoding) : new String(fbos.toByteArray());
        putParameter(header.formFieldName, value);
      }

      input.skipBytes(1);
      input.mark(1);
View Full Code Here


    if (checkUpload() == false) {
      return;
    }
    size = 0;
    if (memoryThreshold > 0) {
      FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream(memoryThreshold + 1);
      int written = input.copyMax(fbaos, memoryThreshold + 1);
      data = fbaos.toByteArray();
      if (written <= memoryThreshold) {
        size = data.length;
        valid = true;
        return;
      }
View Full Code Here

      String fileName = part.getFileName();
      String contentId = (part instanceof MimePart) ? ((MimePart)part).getContentID() : null;
      String mimeType = EmailUtil.extractMimeType(part.getContentType());

      InputStream is = (InputStream) content;
      FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
      StreamUtil.copy(is, fbaos);

      email.addAttachment(fileName, mimeType, contentId, fbaos.toByteArray());
    } else if (content instanceof MimeMessage) {
      MimeMessage mimeMessage = (MimeMessage) content;

      addAttachmentMessage(new ReceivedEmail(mimeMessage));
    }
View Full Code Here

  /**
   * Create object copy using serialization mechanism.
   */
  public static Object cloneViaSerialization(Serializable obj) throws IOException, ClassNotFoundException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    ObjectOutputStream out = null;
    ObjectInputStream in = null;
    Object objCopy = null;

    try {
      out = new ObjectOutputStream(bos);
      out.writeObject(obj);
      out.flush();

      byte[] bytes = bos.toByteArray();

      in = new ObjectInputStream(new ByteArrayInputStream(bytes));
      objCopy = in.readObject();
    } finally {
      StreamUtil.close(out);
View Full Code Here

  /**
   * Serialize an object to byte array.
   */
  public static byte[] objectToByteArray(Object obj) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    ObjectOutputStream oos = null;

    try {
      oos = new ObjectOutputStream(bos);
      oos.writeObject(obj);
    } finally {
      StreamUtil.close(oos);
    }
    return bos.toByteArray();
  }
View Full Code Here

          }
        }
        putFile(header.formFieldName, newFile);
      } else {
        // no file, therefore it is regular form parameter.
        FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
        input.copyAll(fbos);
        String value = encoding != null ? new String(fbos.toByteArray(), encoding) : new String(fbos.toByteArray());
        putParameter(header.formFieldName, value);
      }

      input.skipBytes(1);
      input.mark(1);
View Full Code Here

  /**
   * Reads boundary from the input stream.
   */
  public byte[] readBoundary() throws IOException {
    FastByteArrayOutputStream boundaryOutput = new FastByteArrayOutputStream();
    byte b;
    // skip optional whitespaces
    while ((b = readByte()) <= ' ') {
    }
    boundaryOutput.write(b);

    // now read boundary chars
    while ((b = readByte()) != '\r') {
      boundaryOutput.write(b);
    }
    if (boundaryOutput.size() == 0) {
      throw new IOException("Problems with parsing request: invalid boundary");
    }
    skipBytes(1);
    boundary = new byte[boundaryOutput.size() + 2];
    System.arraycopy(boundaryOutput.toByteArray(), 0, boundary, 2, boundary.length - 2);
    boundary[0] = '\r';
    boundary[1] = '\n';
    return boundary;
  }
View Full Code Here

    return lastHeader;
  }


  protected String readDataHeaderString(String encoding) throws IOException {
    FastByteArrayOutputStream data = new FastByteArrayOutputStream();
    byte b;
    while (true) {
      // end marker byte on offset +0 and +2 must be 13
      if ((b = readByte()) != '\r') {
        data.write(b);
        continue;
      }
      mark(4);
      skipBytes(1);
      int i = read();
      if (i == -1) {
        // reached end of stream
        return null;
      }
      if (i == '\r') {
        reset();
        break;
      }
      reset();
      data.write(b);
    }
    skipBytes(3);
    if (encoding != null) {
      return data.toString(encoding);
    } else {
      return data.toString();
    }
  }
View Full Code Here

  /**
   * Reads data from input stream into byte array and stores file size.
   */
  @Override
  public void processStream() throws IOException {
    FastByteArrayOutputStream out = new FastByteArrayOutputStream();
    size = 0;
    if (maxFileSize == -1) {
      size += input.copyAll(out);
    } else {
      size += input.copyMax(out, maxFileSize + 1);    // one more byte to detect larger files
      if (size > maxFileSize) {
        fileTooBig = true;
        valid = false;
        input.skipToBoundary();
        return;
      }
    }
    data = out.toByteArray();
    size = data.length;
    valid = true;
  }
View Full Code Here

    if (checkUpload() == false) {
      return;
    }
    size = 0;
    if (memoryThreshold > 0) {
      FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream(memoryThreshold + 1);
      int written = input.copyMax(fbaos, memoryThreshold + 1);
      data = fbaos.toByteArray();
      if (written <= memoryThreshold) {
        size = data.length;
        valid = true;
        return;
      }
View Full Code Here

TOP

Related Classes of jodd.io.FastByteArrayOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.