Package com.sun.mail.util

Examples of com.sun.mail.util.LineInputStream


     */
    synchronized boolean uidl(String[] uids) throws IOException {
  Response r = multilineCommand("UIDL", 15 * uids.length);
  if (!r.ok)
      return false;
  LineInputStream lis = new LineInputStream(r.bytes);
  String line = null;
  while ((line = lis.readLine()) != null) {
      int i = line.indexOf(' ');
      if (i < 1 || i >= line.length())
    continue;
      int n = Integer.parseInt(line.substring(0, i));
      if (n > 0 && n <= uids.length)
View Full Code Here


    !ignoreExistingBoundaryParameter)
      throw new MessagingException("Missing boundary parameter");

  try {
      // Skip and save the preamble
      LineInputStream lin = new LineInputStream(in);
      StringBuffer preamblesb = null;
      String line;
      String lineSeparator = null;
      while ((line = lin.readLine()) != null) {
    /*
     * Strip trailing whitespace.  Can't use trim method
     * because it's too aggressive.  Some bogus MIME
     * messages will include control characters in the
     * boundary string.
     */
    int i;
    for (i = line.length() - 1; i >= 0; i--) {
        char c = line.charAt(i);
        if (!(c == ' ' || c == '\t'))
      break;
    }
    line = line.substring(0, i + 1);
    if (boundary != null) {
        if (line.equals(boundary))
      break;
        if (line.length() == boundary.length() + 2 &&
          line.startsWith(boundary) && line.endsWith("--")) {
      line = null// signal end of multipart
      break;
        }
    } else {
        /*
         * Boundary hasn't been defined, does this line
         * look like a boundary?  If so, assume it is
         * the boundary and save it.
         */
        if (line.length() > 2 && line.startsWith("--")) {
      if (line.length() > 4 && allDashes(line)) {
          /*
           * The first boundary-like line we find is
           * probably *not* the end-of-multipart boundary
           * line.  More likely it's a line full of dashes
           * in the preamble text.  Just keep reading.
           */
      } else {
          boundary = line;
          break;
      }
        }
    }

    // save the preamble after skipping blank lines
    if (line.length() > 0) {
        // if we haven't figured out what the line separator
        // is, do it now
        if (lineSeparator == null) {
      try {
          lineSeparator =
        System.getProperty("line.separator", "\n");
      } catch (SecurityException ex) {
          lineSeparator = "\n";
      }
        }
        // accumulate the preamble
        if (preamblesb == null)
      preamblesb = new StringBuffer(line.length() + 2);
        preamblesb.append(line).append(lineSeparator);
    }
      }

      if (preamblesb != null)
    preamble = preamblesb.toString();

      if (line == null) {
    if (allowEmpty)
        return;
    else
        throw new MessagingException("Missing start boundary");
      }

      // save individual boundary bytes for easy comparison later
      byte[] bndbytes = ASCIIUtility.getBytes(boundary);
      int bl = bndbytes.length;
     
      /*
       * Read and process body parts until we see the
       * terminating boundary line (or EOF).
       */
      boolean done = false;
  getparts:
      while (!done) {
    InternetHeaders headers = null;
    if (sin != null) {
        start = sin.getPosition();
        // skip headers
        while ((line = lin.readLine()) != null && line.length() > 0)
      ;
        if (line == null) {
      if (!ignoreMissingEndBoundary)
          throw new MessagingException(
          "missing multipart end boundary");
View Full Code Here

    !ignoreExistingBoundaryParameter)
      throw new MessagingException("Missing boundary parameter");

  try {
      // Skip and save the preamble
      LineInputStream lin = new LineInputStream(in);
      StringBuffer preamblesb = null;
      String line;
      String lineSeparator = null;
      while ((line = lin.readLine()) != null) {
    /*
     * Strip trailing whitespace.  Can't use trim method
     * because it's too aggressive.  Some bogus MIME
     * messages will include control characters in the
     * boundary string.
     */
    int i;
    for (i = line.length() - 1; i >= 0; i--) {
        char c = line.charAt(i);
        if (!(c == ' ' || c == '\t'))
      break;
    }
    line = line.substring(0, i + 1);
    if (boundary != null) {
        if (line.equals(boundary))
      break;
        if (line.length() == boundary.length() + 2 &&
          line.startsWith(boundary) && line.endsWith("--")) {
      line = null// signal end of multipart
      break;
        }
    } else {
        /*
         * Boundary hasn't been defined, does this line
         * look like a boundary?  If so, assume it is
         * the boundary and save it.
         */
        if (line.length() > 2 && line.startsWith("--")) {
      if (line.length() > 4 && allDashes(line)) {
          /*
           * The first boundary-like line we find is
           * probably *not* the end-of-multipart boundary
           * line.  More likely it's a line full of dashes
           * in the preamble text.  Just keep reading.
           */
      } else {
          boundary = line;
          break;
      }
        }
    }

    // save the preamble after skipping blank lines
    if (line.length() > 0) {
        // if we haven't figured out what the line separator
        // is, do it now
        if (lineSeparator == null) {
      try {
          lineSeparator =
        System.getProperty("line.separator", "\n");
      } catch (SecurityException ex) {
          lineSeparator = "\n";
      }
        }
        // accumulate the preamble
        if (preamblesb == null)
      preamblesb = new StringBuffer(line.length() + 2);
        preamblesb.append(line).append(lineSeparator);
    }
      }

      if (preamblesb != null)
    preamble = preamblesb.toString();

      if (line == null) {
    if (allowEmpty)
        return;
    else
        throw new MessagingException("Missing start boundary");
      }

      // save individual boundary bytes for comparison later
      byte[] bndbytes = ASCIIUtility.getBytes(boundary);
      int bl = bndbytes.length;

      /*
       * Compile Boyer-Moore parsing tables.
       */

      // initialize Bad Character Shift table
      int[] bcs = new int[256];
      for (int i = 0; i < bl; i++)
    bcs[bndbytes[i] & 0xff] = i + 1;

      // initialize Good Suffix Shift table
      int[] gss = new int[bl];
  NEXT:
      for (int i = bl; i > 0; i--) {
    int j;  // the beginning index of the suffix being considered
    for (j = bl - 1; j >= i; j--) {
        // Testing for good suffix
        if (bndbytes[j] == bndbytes[j - i]) {
      // bndbytes[j..len] is a good suffix
      gss[j - 1] = i;
        } else {
           // No match. The array has already been
           // filled up with correct values before.
           continue NEXT;
        }
    }
    while (j > 0)
        gss[--j] = i;
      }
      gss[bl - 1] = 1;
      /*
       * Read and process body parts until we see the
       * terminating boundary line (or EOF).
       */
      boolean done = false;
  getparts:
      while (!done) {
    InternetHeaders headers = null;
    if (sin != null) {
        start = sin.getPosition();
        // skip headers
        while ((line = lin.readLine()) != null && line.length() > 0)
      ;
        if (line == null) {
      if (!ignoreMissingEndBoundary)
          throw new MessagingException(
          "missing multipart end boundary");
View Full Code Here

    !ignoreExistingBoundaryParameter)
      throw new MessagingException("Missing boundary parameter");

  try {
      // Skip and save the preamble
      LineInputStream lin = new LineInputStream(in);
      StringBuffer preamblesb = null;
      String line;
      String lineSeparator = null;
      while ((line = lin.readLine()) != null) {
    /*
     * Strip trailing whitespace.  Can't use trim method
     * because it's too aggressive.  Some bogus MIME
     * messages will include control characters in the
     * boundary string.
     */
    int i;
    for (i = line.length() - 1; i >= 0; i--) {
        char c = line.charAt(i);
        if (!(c == ' ' || c == '\t'))
      break;
    }
    line = line.substring(0, i + 1);
    if (boundary != null) {
        if (line.equals(boundary))
      break;
        if (line.length() == boundary.length() + 2 &&
          line.startsWith(boundary) && line.endsWith("--")) {
      line = null// signal end of multipart
      break;
        }
    } else {
        /*
         * Boundary hasn't been defined, does this line
         * look like a boundary?  If so, assume it is
         * the boundary and save it.
         */
        if (line.length() > 2 && line.startsWith("--")) {
      if (line.length() > 4 && allDashes(line)) {
          /*
           * The first boundary-like line we find is
           * probably *not* the end-of-multipart boundary
           * line.  More likely it's a line full of dashes
           * in the preamble text.  Just keep reading.
           */
      } else {
          boundary = line;
          break;
      }
        }
    }

    // save the preamble after skipping blank lines
    if (line.length() > 0) {
        // if we haven't figured out what the line separator
        // is, do it now
        if (lineSeparator == null) {
      try {
          lineSeparator =
        System.getProperty("line.separator", "\n");
      } catch (SecurityException ex) {
          lineSeparator = "\n";
      }
        }
        // accumulate the preamble
        if (preamblesb == null)
      preamblesb = new StringBuffer(line.length() + 2);
        preamblesb.append(line).append(lineSeparator);
    }
      }

      if (preamblesb != null)
    preamble = preamblesb.toString();

      if (line == null) {
    if (allowEmpty)
        return;
    else
        throw new MessagingException("Missing start boundary");
      }

      // save individual boundary bytes for comparison later
      byte[] bndbytes = ASCIIUtility.getBytes(boundary);
      int bl = bndbytes.length;

      /*
       * Compile Boyer-Moore parsing tables.
       */

      // initialize Bad Character Shift table
      int[] bcs = new int[256];
      for (int i = 0; i < bl; i++)
    bcs[bndbytes[i] & 0xff] = i + 1;

      // initialize Good Suffix Shift table
      int[] gss = new int[bl];
  NEXT:
      for (int i = bl; i > 0; i--) {
    int j;  // the beginning index of the suffix being considered
    for (j = bl - 1; j >= i; j--) {
        // Testing for good suffix
        if (bndbytes[j] == bndbytes[j - i]) {
      // bndbytes[j..len] is a good suffix
      gss[j - 1] = i;
        } else {
           // No match. The array has already been
           // filled up with correct values before.
           continue NEXT;
        }
    }
    while (j > 0)
        gss[--j] = i;
      }
      gss[bl - 1] = 1;
      /*
       * Read and process body parts until we see the
       * terminating boundary line (or EOF).
       */
      boolean done = false;
  getparts:
      while (!done) {
    InternetHeaders headers = null;
    if (sin != null) {
        start = sin.getPosition();
        // skip headers
        while ((line = lin.readLine()) != null && line.length() > 0)
      ;
        if (line == null) {
      if (!ignoreMissingEndBoundary)
          throw new MessagingException(
          "missing multipart end boundary");
View Full Code Here

    }

    private void loadProvidersFromStream(InputStream is)
        throws IOException {
  if (is != null) {
      LineInputStream lis = new LineInputStream(is);
      String currLine;

      // load and process one line at a time using LineInputStream
      while ((currLine = lis.readLine()) != null) {

    if (currLine.startsWith("#"))
        continue;
    Provider.Type type = null;
    String protocol = null, className = null;
View Full Code Here

    private int status;
    private String reason;

    public static StatusLine create(DataSource dataSource) {
        try {
            LineInputStream stream = new LineInputStream(
                    dataSource.getInputStream());
            try {
                String line = stream.readLine();
                StringReader lineReader = new StringReader(line);

                expect(lineReader, "HTTP/1.1");
                expect(lineReader, " ");
                String statusString = extractInput(lineReader, ' ');
                String reason = extractInput(lineReader, DELIMITER);

                return new StatusLine().setStatus(
                        Integer.parseInt(statusString)).setReason(reason);
            } finally {
                stream.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.mail.util.LineInputStream

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.