Package java.io

Examples of java.io.InputStream


          ZipEntry entry = (ZipEntry)entries.nextElement();
          if(entry.isDirectory()) {
            (new File(targetDir, entry.getName())).mkdir();
            continue;
          }
          InputStream in = zipFile.getInputStream(entry);
          OutputStream out = new FileOutputStream(new File(targetDir, entry.getName()));   
          try {
            WGUtils.inToOut(in, out, 2048);
          } finally {
            out.close();
            in.close();
          }
        }
        zipFile.close();
    } finally {
        if (zipFile != null) {
View Full Code Here


  public static IndexMetadataFactory loadMetadata(URL vdbURL)
      throws IOException, MalformedURLException, URISyntaxException {
    //vfs has a problem with vdbs embedded in jars in the classpath, so we'll create a temp version
    if (vdbURL.getProtocol().equals("jar")) {
      InputStream is = vdbURL.openStream();
      File temp = File.createTempFile("temp", ".vdb", new File(UnitTestUtil.getTestScratchPath()));
      temp.deleteOnExit();
      FileUtils.write(is, temp);
      vdbURL = temp.toURI().toURL();
    }
View Full Code Here

public class TestXSDCorruption extends TestCase
{

   private void assertHash(String expected, String resourcePath) throws Exception
   {
      InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
      assertNotNull(in);
      byte[] bytes = IOTools.getBytes(in);
      java.security.MessageDigest digester = java.security.MessageDigest.getInstance("MD5");
      digester.update(bytes);
      StringBuilder sb = new StringBuilder();
View Full Code Here

   
 
 
    private Image createImage(String resourcePath) throws IOException {
        InputStream in = null;
        try {
            in = getResourceAsStream(resourcePath);
            return new Image(Display.getCurrent(),in);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {                  
                }
            }
        }      
    }
View Full Code Here

    CharsetUtils.toHex(cb, (byte)chr);
    return cb.append("_").flip().toString()//$NON-NLS-1$
  }

    public static SQLXML jsonToXml(CommandContext context, final String rootName, final Blob json) throws TeiidComponentException, TeiidProcessingException, SQLException, IOException {
    InputStream is = json.getBinaryStream();
    PushbackInputStream pStream = new PushbackInputStream(is, 4);
    byte[] encoding = new byte[3];
    int read = pStream.read(encoding);
    pStream.unread(encoding, 0, read);
    Charset charset = UTF_8;
View Full Code Here

    // System.out.println( "Processor starts: " + socket.getRemoteSocketAddress());
   
    boolean  keep_alive = getServer().isKeepAliveEnabled();
   
    try{
      InputStream  is = new BufferedInputStream( socket.getInputStream());

      while( true ){
       
        setTaskState( "entry" );
       
        try
          if ( keep_alive ){
           
            socket.setSoTimeout( KEEP_ALIVE_SOCKET_TIMEOUT );
           
            setTimeoutsDisabled( true );
           
          }else{
         
            socket.setSoTimeout( SOCKET_TIMEOUT );
          }         
        }catch ( Throwable e ){
                           
          // e.printStackTrace();
        }
                             
        setTaskState( "reading header" );
 
        try{
                               
          byte[]  buffer       = new byte[16*1024];
          int    header_pos    = 0;
         
          while( header_pos < buffer.length ){
             
            int  len = is.read( buffer, header_pos, 1);
             
            if ( len != 1 ){
           
              throw( new Exception( "Premature end of stream reading header" ));
            }
           
            header_pos++;
           
            if (   header_pos >= 4 &&
                buffer[header_pos-4] == CR &&
                buffer[header_pos-3] == FF &&
                buffer[header_pos-2] == CR &&
                buffer[header_pos-1] == FF ){
                 
              break;
            }
          }

          String  header = new String( buffer, 0, header_pos, Constants.BYTE_ENCODING );
     
          if ( Logger.isEnabled()){
           
            String  log_str = header;
           
            int  pos = log_str.indexOf( NL );
           
            if ( pos != -1 ){
             
              log_str = log_str.substring(0,pos);
            }
           
            Logger.log(new LogEvent(LOGID, "Tracker Server: received header '"
                + log_str + "' from " + socket.getRemoteSocketAddress()));
          }       
           
          // System.out.println( "got header:" + header );
         
          InputStream  post_is   = null;
          File    post_file  = null;
         
          String  lowercase_header;
         
          boolean  head  = false;
         
          int  url_start;
         
 
          if ( header.startsWith( "GET " )){
         
            timeout_ticks    = 1;
           
            lowercase_header  = header.toLowerCase();
            url_start      = 4;
           
          }else if ( header.startsWith( "HEAD " )){
           
            timeout_ticks    = 1;
           
            lowercase_header  = header.toLowerCase();     
            url_start      = 5;
 
            head  = true;
           
          }else if ( header.startsWith( "POST ")){
           
            timeout_ticks  = TRTrackerServerTCP.PROCESSING_POST_MULTIPLIER;
           
            if ( timeout_ticks == 0 ){
             
              setTimeoutsDisabled( true );
            }
           
            setTaskState( "reading content" );
           
            lowercase_header  = header.toLowerCase();
            url_start      = 5;
 
            String cl_str = getHeaderField( header, lowercase_header, "content-length:" );
           
            if ( cl_str == null ){
             
              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++){
               
                if (   head_data[i-3]   == CR &&
                    head_data[i-2]   == FF &&
                    head_data[i-1]   == CR &&
                    head_data[i== FF ){
                 
                  header_length = i+1;
             
                  break;
                }
              }
                         
              setTaskState( "writing head response" );
 
              socket.getOutputStream().write( head_data, 0, header_length );
             
              socket.getOutputStream().flush();
             
            }else{
           
              if( !processRequest(
                    header,
                    lowercase_header,
                    url,
                    (InetSocketAddress)socket.getLocalSocketAddress(),
                    (InetSocketAddress)socket.getRemoteSocketAddress(),
                    false,
                    keep_alive,
                    post_is,
                    socket.getOutputStream(),
                    null )){
               
                keep_alive = false;
              }
            }
          }finally{
           
            if ( post_is != null ){
             
              post_is.close();
            }
           
            if ( post_file != null ){
             
              post_file.delete();
View Full Code Here

   */
  private void writeZipEntry(ZipOutputStream zipOut,
                             URLContent content,
                             String entryName) throws IOException {
    byte [] buffer = new byte [8096];
    InputStream contentIn = null;
    try {
      zipOut.putNextEntry(new ZipEntry(entryName));
      contentIn = content.openStream();         
      int size;
      while ((size = contentIn.read(buffer)) != -1) {
        zipOut.write(buffer, 0, size);
      }
      zipOut.closeEntry()
    } finally {
      if (contentIn != null) {         
        contentIn.close();
      }
    }
  }
View Full Code Here

  /**
   * Copy the given <code>content</code> to <code>file</code>.
   */
  private void copyContent(Content content, File file) throws IOException {
    InputStream in = null;
    try {
      in = content.openStream();
      copyContentToFile(in, file);
    } catch (IOException ex) {
      throw new IOException("Can't copy content " + content + " to " + file);
    } finally {
      try {
        if (in != null) {         
          in.close();
        }
      } catch (IOException ex) {
        // Forget exception
      }
    }
View Full Code Here

  /**
   * Copy <code>file1</code> to <code>file2</code>.
   */
  private void copyFile(File file1, File file2) throws IOException {
    InputStream in = null;
    try {
      in = new FileInputStream(file1);
      copyContentToFile(in, file2);
    } catch (IOException ex) {
      throw new IOException("Can't copy file " + file1 + " to " + file2);
    } finally {
      try {
        if (in != null) {         
          in.close();
        }
      } catch (IOException ex) {
        // Forget exception
      }
    }
View Full Code Here

     * Get the version of this FtpServer
     * @return The current version
     */
    public static String getVersion() {
        Properties props = new Properties();
        InputStream in = null;
       
        try {
            in = Version.class.getClassLoader().getResourceAsStream("org/apache/ftpserver/ftpserver.properties");
            props.load(in);
            return props.getProperty("ftpserver.version");
View Full Code Here

TOP

Related Classes of java.io.InputStream

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.