Package java.io

Examples of java.io.ByteArrayOutputStream$Cell


     * @param objectCustomizers
     * @return
     */
    public static final String writeMetadata(Object rootObject,
        Map<Class<? extends Object>, JSONObjectCustomizer> objectCustomizers,boolean isSchema){
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      WSJSONWriter  writter = new WSJSONWriter(out, rootObject, objectCustomizers);
      writter.writeMetadata(JSONCodec.dateFormat, JSONCodec.excludeProperties,
          JSONCodec.includeProperties, JSONCodec.globalMapKeyPattern,
          JSONCodec.globalMapValuePattern, isSchema);
      return out.toString();
  }
View Full Code Here


   }

   //--------------------------------------
   private ByteArrayOutputStream loadInputStream(InputStream input) throws Exception
   {
      ByteArrayOutputStream output = new ByteArrayOutputStream();

      BufferedInputStream buffer = new BufferedInputStream(input);
      byte[] bytes = new byte[buffer.available()];
      int available = -1;
      while ((available = buffer.read(bytes)) > -1)
      {
         output.write(bytes, 0, available);
      }
      return output;
   }
View Full Code Here

   private BufferingOutputStream out = new BufferingOutputStream(bytes, 5);

   @Override
   protected void setUp() throws Exception
   {
      bytes = new ByteArrayOutputStream();
      out = new BufferingOutputStream(bytes, 5);
   }
View Full Code Here

   }

   public void testStreamClose() throws Exception
   {
      final AtomicBoolean closed = new AtomicBoolean(false);
      BufferingOutputStream out = new BufferingOutputStream(new ByteArrayOutputStream()
      {
         @Override
         public void close() throws IOException
         {
            closed.set(true);
View Full Code Here

    if (isSupportedType(transferData)) {
      URLType[] myTypes = (URLType[]) object;
      try {
        // write data to a byte array and then ask super to convert to pMedium
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream writeOut = new DataOutputStream(out);
        for (int i = 0, length = myTypes.length; i < length; i++) {
          writeOut.writeBytes(myTypes[i].linkURL);
          writeOut.writeBytes("\n");
          writeOut.writeBytes(myTypes[i].linkText);
        }
        byte[] buffer = out.toByteArray();
        writeOut.close();

        super.javaToNative(buffer, transferData);

      } catch (IOException e) {
View Full Code Here

        }
      } catch (Throwable e) {
      }

      if (awtImage != null) {
        final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        ImageIO.write((BufferedImage) awtImage, "png", outStream);
        final ByteArrayInputStream inStream = new ByteArrayInputStream(
            outStream.toByteArray());

        image = new Image(Display.getDefault(), inStream);
        if (!bBig) {
          image = force16height(image);
        }
View Full Code Here

        }
        return result;
    }
   
    public static String getStackTrace( final Throwable t ) {
        final ByteArrayOutputStream bas = new ByteArrayOutputStream();
        final PrintWriter pw = new PrintWriter(bas);
        t.printStackTrace(pw);
        pw.close();
        return bas.toString();
    }
View Full Code Here

    return result;
  }
 
  private byte[] writeAsByteArray(Throwable t) {
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
          oos.writeObject(t);
          oos.flush();
          oos.close();
          return baos.toByteArray();
    } catch (IOException e) {
      return null;
    }
  }
View Full Code Here

              throw( new Exception( "Content-Length missing" ));
            }
           
            int content_length = Integer.parseInt( cl_str );
           
            ByteArrayOutputStream  baos    = null;
            FileOutputStream    fos      = null;
         
            OutputStream  data_os;
           
            if ( content_length <= 256*1024 ){
             
              baos = new ByteArrayOutputStream();
           
              data_os  = baos;
             
            }else{
             
              post_file  = AETemporaryFileHandler.createTempFile();
             
              post_file.deleteOnExit();
             
              fos  = new FileOutputStream( post_file );
             
              data_os  = fos;
            }
           
            while( content_length > 0 ){
             
              int  len = is.read( buffer, 0, Math.min( content_length, buffer.length ));
             
              if ( len < 0 ){
               
                throw( new TRTrackerServerException( "premature end of input stream" ));
              }
             
              data_os.write( buffer, 0, len );
             
              content_length -= len;
            }
           
            if ( baos != null ){
             
              post_is = new ByteArrayInputStream(baos.toByteArray());
             
            }else{
             
              fos.close();
             
              post_is = new BufferedInputStream( new FileInputStream( post_file ), 256*1024 );
            }
           
            // System.out.println( "TRTrackerServerProcessorTCP: request data = " + baos.size());
           
          }else{
           
            int  pos = header.indexOf(' ');
           
            if ( pos == -1 ){
             
              throw( new TRTrackerServerException( "header doesn't have space in right place" ));
            }
           
            timeout_ticks    = 1;
             
            lowercase_header  = header.toLowerCase();
            url_start      = pos+1;
          }
         
          setTaskState( "processing request" );
 
          current_request  = header;
         
          try{
            if ( post_is == null ){
             
                // set up a default input stream
             
              post_is = new ByteArrayInputStream(new byte[0]);
            }
           
            int  url_end = header.indexOf( " ", url_start );
           
            if ( url_end == -1 ){
             
              throw( new TRTrackerServerException( "header doesn't have space in right place" ));
            }
                   
            String url = header.substring( url_start, url_end ).trim();
           
            int  nl_pos = header.indexOf( NL, url_end );
           
            if ( nl_pos == -1 ){
             
              throw( new TRTrackerServerException( "header doesn't have nl in right place" ));
            }
           
            String  http_ver = header.substring( url_end, nl_pos ).trim();
           
           
            String con_str = getHeaderField( header, lowercase_header, "connection:" );

            if ( con_str == null ){
             
              if ( http_ver.equalsIgnoreCase( "HTTP/1.0" )){
               
                keep_alive = false;
              }
            }else if ( con_str.equalsIgnoreCase( "close" )){
             
              keep_alive = false;
            }
           
            if ( head ){
             
              ByteArrayOutputStream  head_response = new ByteArrayOutputStream(4096);
             
              if ( !processRequest(
                    header,
                    lowercase_header,
                    url,
                    (InetSocketAddress)socket.getLocalSocketAddress(),
                    (InetSocketAddress)socket.getRemoteSocketAddress(),
                    false,
                    keep_alive,
                    post_is,
                    head_response,
                    null )){
                   
                keep_alive = false;
              }
             
              byte[]  head_data = head_response.toByteArray();
             
              int  header_length = head_data.length;
             
              for (int i=3;i<head_data.length;i++){
               
View Full Code Here

            asyncProcessComplete( async_stream[0] );
          }
        };
     
      try{
        ByteArrayOutputStream  response =
          process(   request_header,
                request_header.toLowerCase(),
                url,
                (InetSocketAddress)socket_channel.socket().getRemoteSocketAddress(),
                TRTrackerServerImpl.restrict_non_blocking_requests,
                new ByteArrayInputStream(new byte[0]),
                async_control );
       
          // two ways of going async
          //  1) return is null and something else will call asyncProcessComplete later
          //  2) return is 'not-yet-filled' os and async controller is managing things
       
        if ( response == null ){
         
          async = true;
         
        }else if ( went_async[0] != null ){
         
          async_stream[0] = response;
         
          async = true;
         
        }else{
         
          write_buffer = ByteBuffer.wrap( response.toByteArray());
        }
      }finally{
       
        if ( went_async[0] != null ){
       
View Full Code Here

TOP

Related Classes of java.io.ByteArrayOutputStream$Cell

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.