Package java.io

Examples of java.io.ByteArrayOutputStream$Cell


    super.tearDown();
  }

  public void testLoadSave()
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manager.save(out);
    System.out.println("Saved to: " + new String(out.toByteArray()));
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    InMemoryUserManager newManager = new InMemoryUserManager(null);
    newManager.load(in);
    UserProfile profile3 = new UserProfile();
    profile3.setUserType(UserProfile.GUEST);
    profile3.setUsername("user3");
View Full Code Here


        if (Logger.isEnabled())
          Logger.log(new LogEvent(LOGID,
              "Accessing scrape interface using url : " + reqUrl));

        ByteArrayOutputStream message = new ByteArrayOutputStream();

        long scrapeStartTime = SystemTime.getCurrentTime();

        URL  redirect_url = null;
       
        String protocol = reqUrl.getProtocol();
       
          URL udpScrapeURL = null;
         
          boolean auto_probe = false;
         
          if (protocol.equalsIgnoreCase("udp")){
           
            if ( udpScrapeEnabled ){
         
              udpScrapeURL = reqUrl;
             
            }else{
             
              throw( new IOException( "UDP Tracker protocol disabled" ));
             
            }
          }else if ( protocol.equalsIgnoreCase("http") &&
              !az_tracker &&
              scrapeCount % autoUDPscrapeEvery == 0 &&
              udpProbeEnabled && udpScrapeEnabled ){
           
            udpScrapeURL = new URL(reqUrl.toString().replaceFirst("^http", "udp"));
           
            auto_probe = true;
          }
         
          try{
              // set context in case authentication dialog is required
           
          TorrentUtils.setTLSTorrentHash(one_of_the_hashes);

            if ( udpScrapeURL != null){
             
              boolean success = scrapeUDP( reqUrl, message, hashesForUDP, !auto_probe );
             
              if((!success || message.size() == 0) && !protocol.equalsIgnoreCase("udp"))
              { // automatic UDP probe failed, use HTTP again
                udpScrapeURL = null;
                message.reset();
                if(autoUDPscrapeEvery < 16)
                  autoUDPscrapeEvery <<= 1;
              if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_INFORMATION, "redirection of http scrape ["+scrapeURL+"] to udp failed, will retry in "+autoUDPscrapeEvery+" scrapes"));
              } else if(success && !protocol.equalsIgnoreCase("udp"))
              {
              if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_INFORMATION, "redirection of http scrape ["+scrapeURL+"] to udp successful"));
                autoUDPscrapeEvery = 1;
                TRTrackerUtils.setUDPProbeResult( reqUrl, true );
              }
               
            }
           
            scrapeCount++;
           
            if(udpScrapeURL == null)
              redirect_url = scrapeHTTP(reqUrl, message);
        }finally{
         
          TorrentUtils.setTLSTorrentHash( null );
        }
       
        scrape_reply = message.toByteArray();
       
        Map map = BDecoder.decode( scrape_reply );
               
        boolean  this_is_az_tracker = map.get( "aztracker" ) != null;
       
View Full Code Here

    
      HttpURLConnection con = (HttpURLConnection)url.openConnection();
     
      con.connect();
     
      ByteArrayOutputStream message = new ByteArrayOutputStream();
      InputStream is = con.getInputStream();
     
      byte[] data = new byte[ 1024 ];
     
      int  expected_length = -1;
           
      while( true ){
       
        int  len = is.read( data );
       
        if ( len <= 0 ){
         
          break;
        }
       
        message.write( data, 0, len );
       
        if ( expected_length == -1 && message.size() >= 4 ){
         
          byte[]  bytes = message.toByteArray();
         
          ByteBuffer  bb = ByteBuffer.wrap( bytes );
         
          expected_length = bb.getInt();
         
          message = new ByteArrayOutputStream();
         
          if ( bytes.length > 4 ){
           
            message.write( bytes, 4, bytes.length - 4 );
          }
        }
       
        if ( expected_length != -1 && message.size() == expected_length ){
         
          break;
        }
      }
     
      Map map = BDecoder.decode( message.toByteArray() );
      int reply_result = ((Long)map.get( "result" )).intValue();
     
      switch( reply_result ) {
        case 0 :{
          byte[] reason = (byte[])map.get( "reason" );
View Full Code Here

                resvp_len  = target_length;
              }
             
              String[] cmd = {"/usr/sbin/xfs_io","-c", "resvsp " + resvp_start + " " + resvp_len, data_file.getAbsolutePath()};
             
              ByteArrayOutputStream os = new ByteArrayOutputStream();
              byte[] buffer = new byte[1024];
              try {
                  Process p = Runtime.getRuntime().exec(cmd);
                  for (int count = p.getErrorStream().read(buffer); count > 0; count = p.getErrorStream().read(buffer)) {
                     os.write(buffer, 0, count);
                  }
                  os.close();
                  p.waitFor();
              } catch (IOException e) {
                String message = MessageText.getString("xfs.allocation.xfs_io.not.found", new String[] {e.getMessage()});
                Logger.log(new LogAlert(this, LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, message));
              }
              if (os.size() > 0) {
                String message = os.toString().trim();
                if (message.endsWith("is not on an XFS filesystem")) {
                  Logger.log(new LogEvent(this, LogIDs.DISK, "XFS file allocation impossible because \"" + data_file.getAbsolutePath()
                      + "\" is not on an XFS filesystem. Original error reported by xfs_io : \"" + message + "\""));
                } else {
                  throw new Exception(message);
View Full Code Here

          if (Logger.isEnabled()){
            Logger.log(new LogEvent(torrent, LOGID,
                "Tracker Announcer is Requesting: " + reqUrl));
          }
         
            ByteArrayOutputStream message = new ByteArrayOutputStream();
           
           
            URL udpAnnounceURL = null;
           
            boolean  udp_probe = false;
           
              // if we have multiple tracker URLs then do something sensible about
           
            if ( protocol.equalsIgnoreCase("udp")){
             
              if ( udpAnnounceEnabled ){
             
                udpAnnounceURL = reqUrl;
               
              }else{
               
                throw( new IOException( "UDP Tracker protocol disabled" ));
              }
           
          }else if protocol.equalsIgnoreCase("http") &&
                !az_tracker  &&
                announceCount % autoUDPprobeEvery == 0 &&
                udpAnnounceEnabled ){
           
              // if we don't know this tracker supports UDP then don't probe on
              // first announce as we don't want a large delay on torrent startup
              // also if we are stopping we don't want to initiate a probe as
              // we want the stop instruction to get to tracker if possible
           
            if (  (   stopped ||
                  announceCount == 0 ||
                  ( announceCount < trackerUrlLists.size() && announceFailCount == announceCount )) &&
                !TRTrackerUtils.isUDPProbeOK(reqUrl)){
             
              // skip probe
             
            }else{
              udpAnnounceURL = new URL(reqUrl.toString().replaceFirst("^http", "udp"));
             
              udp_probe = true;
            }
          }
               
            if ( udpAnnounceURL != null ){
             
            failure_reason = announceUDP( reqUrl, message, udp_probe );
           
            if ((failure_reason != null || message.size() == 0) && udp_probe){
             
                // automatic UDP probe failed, use HTTP again
             
              udpAnnounceURL = null;
             
              if ( autoUDPprobeEvery < 16 ){
           
                autoUDPprobeEvery <<= 1;
              }else{
               
                  // unregister in case the tracker somehow changed its capabilities
           
                TRTrackerUtils.setUDPProbeResult(reqUrl, false);
              }
             
              if (Logger.isEnabled()){
                Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_INFORMATION, "redirection of http announce [" + tracker_url[0] + "] to udp failed, will retry in " + autoUDPprobeEvery + " announces"));
             
            }else if (failure_reason == null && udp_probe){
             
              TRTrackerUtils.setUDPProbeResult(reqUrl, true);
             
              if (Logger.isEnabled()){
                Logger.log(new LogEvent(torrent, LOGID, LogEvent.LT_INFORMATION, "redirection of http announce [" + tracker_url[0] + "] to udp successful"));
              }
             
              autoUDPprobeEvery = 1;
            }
          }
           
            announceCount++;
           
            if ( udpAnnounceURL == null){
             
              failure_reason = announceHTTP( tracker_url, reqUrl, message );
            }
 
              // if we've got some kind of response then return it
           
          if ( message.size() > 0 ){
           
            return( message.toByteArray());
          }
           
          if ( failure_reason == null ){
           
            failure_reason = "No data received from tracker";
View Full Code Here

        // try and set the content-length to that of the compressed data
     
      if ( reply_bytes.length < 512*1024 ){
       
        ByteArrayOutputStream temp = new ByteArrayOutputStream( reply_bytes.length );
       
        GZIPOutputStream gzos = new GZIPOutputStream(temp);
       
        gzos.write( reply_bytes );
       
        gzos.finish();
       
        reply_bytes = temp.toByteArray();
       
        do_gzip = false;
      }
    }
   
View Full Code Here

      throw( new DistributedDatabaseException( "not supported yet!" ));
         
    }else{
     
      try{
        ByteArrayOutputStream  baos = new ByteArrayOutputStream();
       
        ObjectOutputStream  oos = new ObjectOutputStream( baos );
       
        oos.writeObject( obj );
       
        oos.close();
       
        res = baos.toByteArray();
       
      }catch( Throwable e ){
       
        throw( new DistributedDatabaseException( "encoding fails", e ));
      }
View Full Code Here

          continue;
        }
       
        String  name = entry.getName();
     
        ByteArrayOutputStream  output = null;
       
        if ( name.equalsIgnoreCase("azureus.sig")){
         
          output  = new ByteArrayOutputStream();
        }
                       
        byte[]  buffer = new byte[65536];
       
        while( true ){
       
          int  len = zis.read( buffer );
         
          if ( len <= 0 ){
           
            break;
          }
         
          if ( output == null ){
           
            sig.update( buffer, 0, len );
           
          }else{
           
            output.write( buffer, 0, len );
          }
        }
       
        if ( output != null ){
         
          signature = output.toByteArray();
        }
      }
           
      if ( signature == null ){
               
View Full Code Here

   
    boolean  ok = false;
   
    try{
     
      ByteArrayOutputStream  baos = new ByteArrayOutputStream( fileContent.length() + 256 );
     
      if ( found_bom ){
       
          // preserve UTF-8 BOM if it was found
       
        baos.write( new byte[]{ (byte)0xEF, (byte)0xBB, (byte)0xBF });
      }
     
      OutputStreamWriter osw = new OutputStreamWriter( baos );
     
      osw.write( fileContent );
     
      osw.close();
     
      FileOutputStream out = null;
           
      try{
       
        out = new FileOutputStream( plistFile );

          out.writebaos.toByteArray() );
 
      }finally{
       
        if( out != null ){
         
View Full Code Here

  public void
  log(
    Throwable        e )
  {
    try{
      ByteArrayOutputStream  baos = new ByteArrayOutputStream();
     
      PrintWriter  pw = new PrintWriter( new OutputStreamWriter( baos ));
     
      e.printStackTrace( pw );
     
      pw.close();
     
      log( baos.toString());
     
    }catch( Throwable ignore ){
     
    }
  }
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.