Examples of OutputStream


Examples of java.io.OutputStream

        g2d.setTransform(newXform);  
        // draw image centered in panel
        g2d.drawImage(old_img, 0, 0, null);
        // Reset to Original
        g2d.setTransform(origXform);
        OutputStream out = saver.write(ctx, imgURL);
        try{
          ImageIO.write(new_img, "JPG", out);
        }finally{
          out.close();
        }
        return true;
  }
View Full Code Here

Examples of java.io.OutputStream

    }
   
    static public void toFile(Context context, RgbImage rgb, int nQuality, String szPath)
      throws IOException
    {
       OutputStream os = new FileOutputStream(szPath);
       try {
         Bitmap bmp = toBitmap(rgb);
         Bitmap.CompressFormat format = Bitmap.CompressFormat.JPEG;
         szPath = szPath.toLowerCase();
         if (szPath.endsWith("jpg") || szPath.endsWith("jpeg")) { //$NON-NLS-1$ //$NON-NLS-2$
           format = Bitmap.CompressFormat.JPEG;
         } else if (szPath.endsWith("png")) { //$NON-NLS-1$
           format = Bitmap.CompressFormat.PNG;
         }
         bmp.compress(format, nQuality, os);
       } finally {
         os.close();
       }
    }
View Full Code Here

Examples of java.io.OutputStream

      }
    }

    void send(Socket socket, Message msg, long currentTimeMillis) throws IOException {
      InputStream is = null;
      OutputStream os = null;

      try {
        os = socket.getOutputStream();
        // Send the message,
        if (this.logmon.isLoggable(BasicLevel.DEBUG))
          this.logmon.log(BasicLevel.DEBUG,
                          this.getName() + ", write message");
        nos.writeMessage(os, msg, currentTimeMillis);
        // and wait the acknowledge.
        if (this.logmon.isLoggable(BasicLevel.DEBUG))
          this.logmon.log(BasicLevel.DEBUG,
                          this.getName() + ", wait ack");
        is = socket.getInputStream();
        if (is.read() == -1)
          throw new ConnectException("Connection broken");

        if (this.logmon.isLoggable(BasicLevel.DEBUG))
          this.logmon.log(BasicLevel.DEBUG,
                          this.getName() + ", receive ack");
      } finally {
        try {
          os.close();
        } catch (Exception exc) {}
        try {
          is.close();
        } catch (Exception exc) {}
        try {
View Full Code Here

Examples of java.io.OutputStream

    }

    public void run() {
      Socket socket = null;
      InputStream is = null;
      OutputStream os = null;

      try {
        // After a stop we needs to create anew the listen socket.
        if (listen == null) {
          // creates a server socket listening on configured port
          listen = createServerSocket();
        }

        NetworkInputStream nis = new NetworkInputStream();
        while (running) {
          try {
            canStop = true;

            // Get the connection
            try {
              if (this.logmon.isLoggable(BasicLevel.DEBUG))
                this.logmon.log(BasicLevel.DEBUG, this.getName() + ", waiting connection");
              socket = listen.accept();
            } catch (IOException exc) {
              if (this.logmon.isLoggable(BasicLevel.DEBUG))
                this.logmon.log(BasicLevel.DEBUG, this.getName() + ", interrupted");
              continue;
            }
            canStop = false;

            setSocketOption(socket);

            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG, this.getName() + ", connected");

            // Read the message,
            os = socket.getOutputStream();
            is = socket.getInputStream();

            Message msg = nis.readMessage(is);

            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG, this.getName() + ", msg received");

            deliver(msg);

            if (this.logmon.isLoggable(BasicLevel.DEBUG))
              this.logmon.log(BasicLevel.DEBUG, this.getName() + ", send ack");

            // then send the acknowledge.
            os.write(0);
            os.flush();
          } catch (Exception exc) {
            this.logmon.log(BasicLevel.ERROR, this.getName() + ", closed", exc);
          } finally {
            nis.clean();
            try {
              if (os != null) os.close();
            } catch (Exception exc) {}
            os = null;
            try {
              if (is != null) is.close();
            } catch (Exception exc) {}
View Full Code Here

Examples of java.io.OutputStream

    socket.setSoTimeout(params.SoTimeout);
    if (params.SoLinger >= 0)
      socket.setSoLinger(true, params.SoLinger);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputStream os = socket.getOutputStream();
    InputStream is = socket.getInputStream();

    // Writes the Joram magic number
    baos.write(MetaData.joramMagic);
    // Writes the current date
    StreamUtil.writeTo(System.currentTimeMillis(), baos);

    // Writes the user identity
    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG, " -> write identity = " + identity);
    Identity.write(identity, baos);

    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG, " -> write key = " + key);
    StreamUtil.writeTo(key, baos);

    if (key == -1) {
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, " -> connection opened, initializes new connection");
      StreamUtil.writeTo(reconnectTimeout, baos);
      baos.writeTo(os);
      os.flush();

      int len = StreamUtil.readIntFrom(is);
      long dt = StreamUtil.readLongFrom(is);
      if (dt > clockSynchroThreshold)
        logger.log(BasicLevel.WARN, " -> bad clock synchronization between client and server: " + dt);

      int res = StreamUtil.readIntFrom(is);
      if (res > 0) {
        String info = StreamUtil.readStringFrom(is);
        throwSecurityError(info);
      }

      key = StreamUtil.readIntFrom(is);
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, " -> key = " + identity.getUserName() + ',' + key);
      connection = new ReliableTcpConnection(timer);
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, " -> init reliable connection");
    } else {
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, " -> reinitializes connection " + identity + ',' + key);
      baos.writeTo(os);
      os.flush();

      int len = StreamUtil.readIntFrom(is);
      int res = StreamUtil.readIntFrom(is);
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, " -> read res = " + res);
View Full Code Here

Examples of java.io.OutputStream

       + MODEL_FILE_EXTENSION);
      }
      m_Log.statusMessage("Saving model to file...");
     
      try {
  OutputStream os = new FileOutputStream(sFile);
  if (sFile.getName().endsWith(".gz")) {
    os = new GZIPOutputStream(os);
  }
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(os);
  objectOutputStream.writeObject(classifier);
View Full Code Here

Examples of java.io.OutputStream

            writeItemToSAX(handler);
        } else if(result instanceof StreamResult) {
            StreamResult streamResult = (StreamResult) result;
            final Writer writer = streamResult.getWriter();
            if(writer == null) {
                OutputStream os = streamResult.getOutputStream();
                writeItem(os, new Properties());
            } else {
                writeItem(writer, new Properties());
            }
        } else {
View Full Code Here

Examples of java.io.OutputStream

    }
   
    super.saveChanges();
   
    if (_schema != null) {
        OutputStream out = new FileOutputStream(getSchemaDefinitionFile().getLocation().toFile());
        try {
            _schema.write(out);
        } catch (Exception e) {
            IOException ioe = new IOException("Unable to save design config changes.");
              ioe.setStackTrace(e.getStackTrace());
              throw ioe;
        } finally {
            out.close();
        }
    }
   
    try {
      new WGADesignStructureHelper(_designContainer).enforceDesignEncoding();
View Full Code Here

Examples of java.io.OutputStream

                    charset = new MediaType.Parameter(CHARSET_KEY, m_characterCode);
                }
                m_response.setContentType(contentType.toStringWithParams(new MediaType.Parameter[]{charset}));

                // set up the actual writer
                OutputStream outputStream = m_response.getOutputStream();
                if (m_interceptor != null) {
                    outputStream = m_interceptor.intercept(outputStream);
                }
               
                m_buffer.setOutput(outputStream);
View Full Code Here

Examples of java.io.OutputStream

        /** {@inheritDoc} */
        public IXMLWriter getNormalWriter(String[] uris) throws IOException, WsException {
            if (m_writer == null) {
                m_buffer = (OutByteBuffer)m_outBufferCache.getInstance();

                OutputStream outputStream = m_connection.getOutputStream();
                if (m_interceptor != null) {
                    outputStream = m_interceptor.intercept(outputStream);
                }
                m_buffer.setOutput(outputStream);
                m_writer = m_codecCache.getCodec(m_msgProps.getContentType()).getWriter(m_buffer, null, uris);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.