Package com.sun.mail.util

Examples of com.sun.mail.util.UUDecoderStream


  public void run()
  {
    Vector<byte[]> outVector = new Vector<byte[]>();
    HelloYenc yencDecoder = null;
    UUDecoderStream uuDecoder = null;
    FileOutputStream fileOutStream = null;
    int uuLength = 0;

    // prepare suitable decoder
    if(encoding.equals("yenc"))
      yencDecoder = new HelloYenc(logger);
    else if(encoding.equals("uu"))
      uuDecoder = null;
    else
    {
      logger.msg("Could not find a suitable decoder!", MyLogger.SEV_ERROR);
      return;
    }

    try
    {
      int i = 0;
      while(articleData.size() > 0)
      {
        // check for corrupt download
        if(articleData.get(0) == null || articleData.get(0).length == 0)
        {
          logger.msg("FileDecoder: Corrupt data found", MyLogger.SEV_WARNING);
          articleData.remove(0);
          continue;
        }

        // set data input stream of the yenc decoder object
        if(encoding.equals("yenc"))
        {
          yencDecoder.setInputData(articleData.get(0));
          yencDecoder.setPartNum(i + 1);
          yencDecoder.setRunnable(this);
        }

        // set data for the UUDecoder object
        else if(encoding.equals("uu"))
        {
          byte[] src = articleData.get(0);
          uuLength = src.length;
          ByteArrayInputStream inStream = new ByteArrayInputStream(src);
          uuDecoder = new UUDecoderStream(inStream);
        }

        // do we have the first (yenc) part loaded (then get filename)?
        if(i == 0)
        {
          File resultFile = createOutFile(yencDecoder, uuDecoder);
          fileOutStream = new FileOutputStream(resultFile);
        }

        // now decode the current article data block
        if(articleData.get(0).length > 0)
        {
          if(encoding.equals("yenc"))
            outVector.add(yencDecoder.decode());

          else if(encoding.equals("uu"))
          {
            byte[] bytes = new byte[uuLength];
            int b;

            b = uuDecoder.read();
            int outBufCounter = 0;
            for(; b != -1 && outBufCounter < uuLength; outBufCounter++)
            {
              bytes[outBufCounter] = (byte) b;
              b = uuDecoder.read();
            }

            byte[] newOutBuf = new byte[outBufCounter];
            System.arraycopy(bytes, 0, newOutBuf, 0, outBufCounter);
            outVector.add(newOutBuf);
View Full Code Here


    /**
     * Test that data in the test case.
     */
    public static void test(TestCase t) throws Exception {
  InputStream in =
      new UUDecoderStream(new ByteArrayInputStream(t.input),
        t.ignoreErrors, t.ignoreMissingBeginEnd);

  // two cases - either we're expecting an exception or we're not
  if (t.expectedException != null) {
      try {
    int c;
    while ((c = in.read()) >= 0)
        // throw it away
    // read all the data with no exception - fail
    System.out.println("Test: " + t.name);
    System.out.println("Got no Exception");
    System.out.println("Expected Exception: " +
            t.expectedException);
    errors++;
      } catch (Exception ex) {
    if (!ex.getClass().getName().equals(t.expectedException)) {
        System.out.println("Test: " + t.name);
        System.out.println("Got Exception: " + ex);
        System.out.println("Expected Exception: " +
          t.expectedException);
        errors++;
    }
      } finally {
    try {
        in.close();
    } catch (IOException ioex) { }
      }
  } else {
      InputStream ein = new ByteArrayInputStream(t.expectedOutput);
      try {
    int c, ec;
    boolean gotError = false;
    while ((c = in.read()) >= 0) {
        ec = ein.read();
        if (ec < 0) {
      System.out.println("Test: " + t.name);
      System.out.println("Got char: " + c);
      System.out.println("Expected EOF");
      errors++;
      gotError = true;
      break;
        }
        if (c != ec) {
      System.out.println("Test: " + t.name);
      System.out.println("Got char: " + c);
      System.out.println("Expected char: " + ec);
      errors++;
      gotError = true;
      break;
        }
    }
    if (!gotError) {
        ec = ein.read();
        if (ec >= 0) {
      System.out.println("Test: " + t.name);
      System.out.println("Got EOF");
      System.out.println("Expected char: " + ec);
      errors++;
        }
    }
      } catch (Exception ex) {
    System.out.println("Test: " + t.name);
    System.out.println("Got Exception: " + ex);
    System.out.println("Expected no Exception");
    errors++;
      } finally {
    try {
        in.close();
    } catch (IOException ioex) { }
    try {
        ein.close();
    } catch (IOException ioex) { }
      }
View Full Code Here

TOP

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

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.