Package java.io

Examples of java.io.OutputStream


      TestLogger.log("Error creating new summary file: "
        + summaryFile.getAbsolutePath());
      throw ioe;
  }

  OutputStream os = new FileOutputStream(summaryFile);
  os = new BufferedOutputStream(os);
  return new PrintStream(os);
    }
View Full Code Here


*/
   
    PdfContents(PdfContentByte under, PdfContentByte content, PdfContentByte text, PdfContentByte secondContent, Rectangle page) throws BadPdfFormatException {
        super();
        try {
            OutputStream out = null;
            streamBytes = new ByteArrayOutputStream();
            if (Document.compress)
            {
                compressed = true;
                compressionLevel = text.getPdfWriter().getCompressionLevel();
                out = new DeflaterOutputStream(streamBytes, new Deflater(compressionLevel));
            }
            else
                out = streamBytes;
            int rotation = page.getRotation();
            switch (rotation) {
                case 90:
                    out.write(ROTATE90);
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getTop())));
                    out.write(' ');
                    out.write('0');
                    out.write(ROTATEFINAL);
                    break;
                case 180:
                    out.write(ROTATE180);
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getRight())));
                    out.write(' ');
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getTop())));
                    out.write(ROTATEFINAL);
                    break;
                case 270:
                    out.write(ROTATE270);
                    out.write('0');
                    out.write(' ');
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getRight())));
                    out.write(ROTATEFINAL);
                    break;
            }
            if (under.size() > 0) {
                out.write(SAVESTATE);
                under.getInternalBuffer().writeTo(out);
                out.write(RESTORESTATE);
            }
            if (content.size() > 0) {
                out.write(SAVESTATE);
                content.getInternalBuffer().writeTo(out);
                out.write(RESTORESTATE);
            }
            if (text != null) {
                out.write(SAVESTATE);
                text.getInternalBuffer().writeTo(out);
                out.write(RESTORESTATE);
            }
            if (secondContent.size() > 0) {
                secondContent.getInternalBuffer().writeTo(out);
            }
            out.close();
        }
        catch (Exception e) {
            throw new BadPdfFormatException(e.getMessage());
        }
        put(PdfName.LENGTH, new PdfNumber(streamBytes.size()));
View Full Code Here

  private File writeNewAppBitsToTempFile(ContentServices contentServices,
      ResourcePackageDetails packageDetails) throws Exception {
    File tempDir = this.resourceContext.getTemporaryDirectory();
    File tempFile = new File(tempDir, this.deploymentFile.getName());

    OutputStream tempOutputStream = null;
    try {
      tempOutputStream = new BufferedOutputStream(new FileOutputStream(
          tempFile));
      long bytesWritten = contentServices.downloadPackageBits(
          this.resourceContext.getContentContext(), packageDetails
              .getKey(), tempOutputStream, true);
      log
          .debug("Wrote " + bytesWritten + " bytes to '" + tempFile //$NON-NLS-1$ //$NON-NLS-2$
              + "'."); //$NON-NLS-1$
    } catch (IOException e) {
      log.error(
          "Error writing updated application bits to temporary location: " //$NON-NLS-1$
              + tempFile, e);
      throw e;
    } finally {
      if (tempOutputStream != null) {
        try {
          tempOutputStream.close();
        } catch (IOException e) {
          log.error("Error closing temporary output stream", e); //$NON-NLS-1$
        }
      }
    }
View Full Code Here

        if (inputStream != null) {
            rawLength = 0;
            DeflaterOutputStream def = null;
            OutputStreamCounter osc = new OutputStreamCounter(os);
            OutputStreamEncryption ose = null;
            OutputStream fout = osc;
            if (crypto != null)
                fout = ose = crypto.getEncryptionStream(fout);
            if (compressed)   
                fout = def = new DeflaterOutputStream(fout, new Deflater(compressionLevel), 0x8000);
           
            byte buf[] = new byte[4192];
            while (true) {
                int n = inputStream.read(buf);
                if (n <= 0)
                    break;
                fout.write(buf, 0, n);
                rawLength += n;
            }
            if (def != null)
                def.finish();
            if (ose != null)
View Full Code Here

    } catch (SQLException e1) {
      e1.printStackTrace();
    }
  File resultsFile = createNewResultsFile(queryID, querySetID,
    getGenerateDir());
  OutputStream outputStream;
  try {
      FileOutputStream fos = new FileOutputStream(resultsFile);
      outputStream = new BufferedOutputStream(fos);
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to open new results file: " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  }

  try {
      XMLQueryVisitationStrategy jstrat = new XMLQueryVisitationStrategy();

      // Create root JDOM element
      Element rootElement = new Element(TagNames.Elements.ROOT_ELEMENT);

      // Create Query element
      Element queryElement = new Element(TagNames.Elements.QUERY);
      queryElement.addContent(new CDATA(query));
      rootElement.addContent(queryElement);

      // create a result attribute for the queryID
      Attribute resultsIDAttribute = new Attribute(
        TagNames.Attributes.NAME, queryID);

      if (result != null) {
    // produce a JDOM element from the results object
    Element resultsElement = jstrat.produceResults(result);
    // set the resultsIDAttribute on the results element
    resultsElement.setAttribute(resultsIDAttribute);
    // add the results elements to the root element
    rootElement.addContent(resultsElement);
    // debug:
    // System.out.println("\n Result: " + printResultSet(result));
      } else {
    // create a JDOM element from the exception object with the
    // results tag
    Element exceptionElement = new Element(
      TagNames.Elements.QUERY_RESULTS);
    // produce xml for the actualException and this to the
    // exceptionElement
    if (ex != null) {
        exceptionElement.addContent(jstrat.produceMsg(ex, null));
    }
    // set the resultsIDAttribute on the exception element
    exceptionElement.setAttribute(resultsIDAttribute);
    // add the results elements to the root element
    rootElement.addContent(exceptionElement);

      }

      // Output xml
      XMLOutputter outputter = new XMLOutputter(JdomHelper.getFormat(
        "  ", true)); //$NON-NLS-1$
      outputter.output(new Document(rootElement), outputStream);

  } catch (SQLException e) {
      throw new QueryTestFailedException(
        "Failed to convert results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (JDOMException e) {
      throw new QueryTestFailedException(
        "Failed to convert results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to output new results to " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  } catch (Throwable e) {
      throw new QueryTestFailedException(
        "Failed to convert results to JDOM: " + StringUtil.getStackTrace(e)); //$NON-NLS-1$
  } finally {
      try {
    outputStream.close();
      } catch (IOException e) {
      }
  }
    }
View Full Code Here

     */
    private void generateErrorResults(String querySetID, String queryID,
      String sql, File resultsFile, ResultSet actualResult,
      File expectedResultFile, Throwable ex)
      throws QueryTestFailedException {
  OutputStream outputStream;
  try {
      FileOutputStream fos = new FileOutputStream(resultsFile);
      outputStream = new BufferedOutputStream(fos);
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to open error results file: " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  }

  try {
      XMLQueryVisitationStrategy jstrat = new XMLQueryVisitationStrategy();

      // Create root JDOM element
      Element rootElement = new Element(TagNames.Elements.ROOT_ELEMENT);

      // create a JDOM element for the results
      Element resultElement = new Element(TagNames.Elements.QUERY_RESULTS);
      // set the queryIDAttr on the exception element
      resultElement.setAttribute(new Attribute(TagNames.Attributes.NAME,
        queryID));
      // set the querySQLAttr on the exception element
      resultElement.setAttribute(new Attribute(TagNames.Attributes.VALUE,
        sql));

      // ---------------------
      // Actual Exception
      // ---------------------
      // create a JDOM element from the actual exception object
      // produce xml for the actualException and this to the
      // exceptionElement
      if (ex != null) {
    Element actualExceptionElement = new Element(
      TagNames.Elements.ACTUAL_EXCEPTION);

    actualExceptionElement = XMLQueryVisitationStrategy
      .jdomException(ex, actualExceptionElement);
    resultElement.addContent(actualExceptionElement);
      }

      if (actualResult != null) {
    // ------------------------------
    // Got a ResultSet from server
    // error was in comparing results
    // ------------------------------

    // --------------------------
    // Actual Result - ResultSet
    // --------------------------
    // produce a JDOM element from the actual results object
    Element actualResultsElement = new Element(
      TagNames.Elements.ACTUAL_QUERY_RESULTS);
    actualResultsElement = jstrat.produceMsg(actualResult,
      actualResultsElement);

    // add the results elements to the root element
    resultElement.addContent(actualResultsElement);

    // ---------------------
    // Expected Results - ...
    // ---------------------
    // produce xml for the expected results
    // Get expected results
    Element expectedResult = new Element("bogus"); //$NON-NLS-1$
    expectedResult = jstrat.parseXMLResultsFile(expectedResultFile,
      expectedResult);
    if (expectedResult.getChild(TagNames.Elements.SELECT) != null) {
        //----------------------------------------------------------
        // -
        // Expected result was a ResultSet set element name to
        // reflect
        //----------------------------------------------------------
        // -
        expectedResult
          .setName(TagNames.Elements.EXPECTED_QUERY_RESULTS);
    } else {
        //----------------------------------------------------------
        // --
        // Expected result was an exception set element name to
        // reflect
        //----------------------------------------------------------
        // --
        expectedResult
          .setName(TagNames.Elements.EXPECTED_EXCEPTION);
    }
    resultElement.addContent(expectedResult);
      } else {

    // ---------------------
    // Expected Results - ...
    // ---------------------
    // produce xml for the expected results
    // Get expected results
    Element expectedResult = new Element("bogus"); //$NON-NLS-1$
    expectedResult = jstrat.parseXMLResultsFile(expectedResultFile,
      expectedResult);
    if (expectedResult.getChild(TagNames.Elements.SELECT) != null) {
        //----------------------------------------------------------
        // -
        // Expected result was a ResultSet set element name to
        // reflect
        //----------------------------------------------------------
        // -
        expectedResult
          .setName(TagNames.Elements.EXPECTED_QUERY_RESULTS);
    } else {
        //----------------------------------------------------------
        // --
        // Expected result was an exception set element name to
        // reflect
        //----------------------------------------------------------
        // --
        expectedResult
          .setName(TagNames.Elements.EXPECTED_EXCEPTION);
    }
    resultElement.addContent(expectedResult);
      }

      // ------------------------------
      // Got an exeption from the server
      // error was in comparing exceptions
      // ------------------------------

      // add the results elements to the root element
      rootElement.addContent(resultElement);

      // Output xml
      XMLOutputter outputter = new XMLOutputter(JdomHelper.getFormat(
        "  ", true)); //$NON-NLS-1$
      outputter.output(new Document(rootElement), outputStream);

  } catch (SQLException e) {
      throw new QueryTestFailedException(
        "Failed to convert error results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (JDOMException e) {
      throw new QueryTestFailedException(
        "Failed to convert error results to JDOM: " + e.getMessage()); //$NON-NLS-1$
  } catch (IOException e) {
      throw new QueryTestFailedException(
        "Failed to output error results to " + resultsFile.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
  } catch (Throwable e) {
      throw new QueryTestFailedException(
        "Failed to convert error results to JDOM: " + StringUtil.getStackTrace(e)); //$NON-NLS-1$
  } finally {
      try {
    outputStream.close();
      } catch (IOException e) {
      }
  }
    }
View Full Code Here

   * InputStream object
   */
  public void createFile(String fileName, InputStream fis) throws CvFileException
  {
    // check if working dir and location is set
    OutputStream fos;
    File fl;
    try {
      if (fis == null || fis.available() < 0) {
        return;
      }
      fl = new File(this.fullWorkingPath + fileName);

      if (!fl.createNewFile()) {
        throw new CvFileException(CvFileException.COULD_NOT_CREATE_DIRECTORY, "Could not create file");
      }

      fos = new FileOutputStream(fl);

      try {
        int i = 0;
        while ((i = fis.read()) != -1) {
          fos.write(i);
        }
      } catch (Exception e) {
        fis.close();
        fos.close();
        System.out.println("[Exception] CvDiskOperation.createFile: " + e.toString());
        e.printStackTrace();
        throw new CvFileException(CvFileException.OTHER_EXCEPTION, "Other exception");
      }
      fos.close();
      fis.close();
    } catch (Exception e) {
      System.out.println("[Exception] CvDiskOperation.createFile: " + e.toString());
      e.printStackTrace();
      throw new CvFileException(CvFileException.OTHER_EXCEPTION, "Other exception");
View Full Code Here

     *
     * @return the saved properties
     */
    public Properties save() {
        try {
            OutputStream out = fs.openFileOutputStream(fileName, false);
            try {
                properties.store(out, MAGIC);
            } finally {
                out.close();
            }
            lastWrite = fs.getLastModified(fileName);
            if (trace.isDebugEnabled()) {
                trace.debug("save " + properties);
            }
View Full Code Here

        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
    }

    public void testTimeoutForStore() throws Exception {
        OutputStream os = client.storeFileStream(TEST_FILENAME);
       
        os.write(1);
       
        // make sure this take longer than the timeout time, but not timeout between writes...
        for(int i = 0; i<100; i++) {
            Thread.sleep(20);
            os.write(1);  
            os.flush();
        }
       
        os.close();

        client.completePendingCommand();
       
        // we should not have been disconnected
        client.noop();
View Full Code Here

        }
    }
   
    private static class MyFTPClient extends FTPClient {
        public void sendRawCommand(byte[] b) throws IOException {
            OutputStream out =_socket_.getOutputStream();
            out.write(b);
        }
View Full Code Here

TOP

Related Classes of java.io.OutputStream

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.