Package java.io

Examples of java.io.FileInputStream


  static void loadConnectionProperties() {
    if (p != null) {
      return;
    }
      Properties props = new Properties();
      FileInputStream fis = null;
      try {
        fis = new FileInputStream("connection.properties"); //$NON-NLS-1$
        props.load(fis);
      } catch (IOException e) {
        log.log(Level.WARNING, "Could not load default connection properties.", e); //$NON-NLS-1$
      } finally {
        if (fis != null) {
          try {
          fis.close();
        } catch (IOException e) {
        }
        }
      }     
      p = props;
View Full Code Here


 
  @Doc(text = "Deploy a VDB from file")
  public static void deployVDB(
      @Doc(text = "file name") String vdbFile) throws AdminException, FileNotFoundException {
    File file = new File(vdbFile);
    FileInputStream fis = new FileInputStream(file);
    try {
      getAdmin().deployVDB(file.getName(), fis);
    } finally {
      try {
        fis.close();
      } catch (IOException e) {
      }
    }
  }
View Full Code Here

      response.setContentType(mimeType);
     
      if (possibleCached.exists()) {
        // send content
        byte[] buffer = new byte[(int) possibleCached.length()];
        FileInputStream fis = new FileInputStream(possibleCached);
        fis.read(buffer);
        fis.close();
        response.getOutputStream().write(buffer);
        response.getOutputStream().flush();
        response.getOutputStream().close();
      } else {

        BufferedImage image = ImageIO.read(tfile);

        BufferedImage myImage =
          new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics g = myImage.getGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, w, h);

        int width = image.getWidth();
        int height = image.getHeight();

        if (width > height) {
          Image newImage =
            image.getScaledInstance(w, -1, Image.SCALE_SMOOTH);
          g.drawImage(
            newImage,
            0,
            (h - newImage.getHeight(null)) / 2,
            null);
        } else {
          Image newImage =
            image.getScaledInstance(-1, h, Image.SCALE_SMOOTH);
          g.drawImage(
            newImage,
            (w - newImage.getWidth(null)) / 2,
            0,
            null);
        }

        ImageIO.write(myImage, "jpg", possibleCached);
        ImageIO.write(myImage, "jpg", response.getOutputStream());
        response.getOutputStream().flush();
        response.getOutputStream().close();
      }

    } else {

      // retrieve mime type
      String mimeType =
        FileTypeMap.getDefaultFileTypeMap().getContentType(tfile);
      response.setContentType(mimeType);

      // send content
      byte[] buffer = new byte[(int) tfile.length()];
      FileInputStream fis = new FileInputStream(tfile);
      fis.read(buffer);
      fis.close();
      response.getOutputStream().write(buffer);
      response.getOutputStream().flush();
      response.getOutputStream().close();

    }
View Full Code Here

        File dir = new File(root, bean.getDirectory());
        File[] files = dir.listFiles();
        for (int k = 0; k < files.length; k++) {
          File file = files[k];
          if (file.isFile()) {
            InputStream in = new FileInputStream(file);
            ZipEntry ze =
              new ZipEntry(
                "resources/"
                  + bean.getId()
                  + "/"
                  + file.getName());
            zip.putNextEntry(ze);

            // Transfer bytes from the file to the ZIP file
            int len;
            while ((len = in.read(buf)) > 0) {
              zip.write(buf, 0, len);
            }

            zip.closeEntry();
            in.close();
          }
        }
      }

      // add images
      File root =
        new File(getServletContext().getRealPath("/"), imagesPath);
      File[] files = root.listFiles();
      for (int k = 0; k < files.length; k++) {
        File file = files[k];
        if (file.isFile()) {
          InputStream in = new FileInputStream(file);
          ZipEntry ze = new ZipEntry("images/" + file.getName());
          zip.putNextEntry(ze);

          // Transfer bytes from the file to the ZIP file
          int len;
          while ((len = in.read(buf)) > 0) {
            zip.write(buf, 0, len);
          }

          zip.closeEntry();
          in.close();
        }
      }

      // add sections
      Mapping.begin();
View Full Code Here

  private static ResourceXmlBean bean;
 
  public static ResourceXmlBean getResourceXmlBean(HttpServlet servlet, String id) throws Exception {
    if( bean == null ) {
      FileInputStream fis = new FileInputStream( new File(servlet.getServletContext().getRealPath("../../../conf/resources.xml")) );
      bean = ResourceXmlBean.parse(fis);
      fis.close();
    }
    return bean.getResource(id);
  }
View Full Code Here

    return bean.getResource(id);
  }
 
  public static Vector getResourceXmlBeans(HttpServlet servlet) throws Exception {
    if( bean == null ) {
      FileInputStream fis = new FileInputStream( new File(servlet.getServletContext().getRealPath("../../../conf/resources.xml")) );
      bean = ResourceXmlBean.parse(fis);
      fis.close();
    }
    return bean.getItems();
  }
View Full Code Here

  private static TypeBean bean;
 
  public static TypeBean getSectionBean(HttpServlet servlet, String template) throws Exception {
    if( bean == null ) {
      FileInputStream fis = new FileInputStream( new File(servlet.getServletContext().getRealPath("../../../conf/templates.xml")) );
      bean = TypeBean.parse(fis);
      fis.close();
    }
    return bean.getBean(template);
  }
View Full Code Here

    return bean.getBean(template);
  }
 
  public static Vector getSectionsBeans(HttpServlet servlet) throws Exception {
    if( bean == null ) {
      FileInputStream fis = new FileInputStream( new File(servlet.getServletContext().getRealPath("../../../conf/templates.xml")) );
      bean = TypeBean.parse(fis);
      fis.close();
    }
    return bean.getItems();
  }
View Full Code Here

        {
            System.err.println( "usage: java org.pdfbox.cmapparser.CMapParser <CMAP File>" );
            System.exit( -1 );
        }
        CMapParser parser = new CMapParser(  );
        CMap result = parser.parse( new FileInputStream( args[0] ) );
        System.out.println( "Result:" + result );
    }
View Full Code Here

        helpTestProcess("SELECT * FROM xmltest.doc9 WHERE OrderID='5' OR OrderID='2'", expectedDoc, metadata, dataMgr);         //$NON-NLS-1$
    }
   
    public static String readFile(String fileName) throws Exception {
        FileInputStream fis = new FileInputStream(UnitTestUtil.getTestDataFile(fileName));
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
        int c = 0;
        while ((c = fis.read()) != -1) {
            baos.write(c);
        }
       
        return baos.toString();
    }
View Full Code Here

TOP

Related Classes of java.io.FileInputStream

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.