Package java.io

Examples of java.io.FileInputStream


        final int nIntByteSize = Integer.SIZE / Byte.SIZE;
        final int nShortByteSize = Short.SIZE / Byte.SIZE;
        try {
            load_from_file(szUnicharFile);
            loadPffmTable(szPfmTable);
            FileInputStream fis = new FileInputStream(szIntTempFile);
            ByteBuffer bb = ByteBuffer.allocate(nIntByteSize * 3);
            ByteOrder bo = ByteOrder.BIG_ENDIAN;
            fis.read(bb.array());
            IntBuffer ib = bb.asIntBuffer();
            boolean swap = (ib.get(2) < 0 || ib.get(2) > MAX_NUM_CLASS_PRUNERS);
            if (swap) {
                bo = ByteOrder.LITTLE_ENDIAN;
                bb.order(bo);
                ib = bb.asIntBuffer();
            }
            int unicharset_size = ib.get(0);
            int NumClasses = ib.get(1);
            int NumClassPruners = ib.get(2);
            int version_id = 0;
            if (NumClasses < 0) {
                // handle version id
                version_id = -NumClasses;
                fis.read(bb.array(), 0, 4);
                NumClasses = ib.get(0);
            }   
            //this.ClassPruner.ensureCapacity(NumClassPruners);
            bb = ByteBuffer.allocate(nShortByteSize * unicharset_size);
            bb.order(bo);
            fis.read(bb.array());
            ShortBuffer sb = bb.asShortBuffer();
            for (int i=0; i<unicharset_size; i++) {
                this.IndexFor[i] = sb.get(i);
            }
            bb = ByteBuffer.allocate(nIntByteSize * NumClasses);
            bb.order(bo);
            fis.read(bb.array());
            ib = bb.asIntBuffer();
            for (int i=0; i<NumClasses; i++) {
                this.ClassIdFor[i] = ib.get(i);
            }
            ArrayList<byte[][][][]> ClassPruners = new ArrayList<byte[][][][]>();
            for (int i=0; i<NumClassPruners; i++) {
                byte[][][][] Pruner =
                        new byte[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][];
                bb = ByteBuffer.allocate(nIntByteSize * NUM_CP_BUCKETS *
                        NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR);
                bb.order(bo);
                fis.read(bb.array());
                ib = bb.asIntBuffer();
                int p = 0;
                for (int j=0; j<NUM_CP_BUCKETS; j++) {
                    for (int k=0; k<NUM_CP_BUCKETS; k++) {
                        for (int l=0; l<NUM_CP_BUCKETS; l++) {
View Full Code Here


        ori_width = old_width * ori_height / old_height;
      }
      if(regenerate_img){ 
        photo.setWidth(ori_width);
        photo.setHeight(ori_height);
        ImageUtils.createPreviewImage(new FileInputStream(origionalPath),
            origionalPath, ori_width, ori_height);
        photo.setSize((int)new File(origionalPath).length());
      }
    }
   
    //��������ͼ�����ʺϳߴ�
    int preview_width, preview_height;
    preview_width = Math.min(PREVIEW_WIDTH, photo.getWidth());
    if(photo.getHeight() <= PREVIEW_HEIGHT)
      preview_height = photo.getHeight();
    else{
      //��������ͼ��߶Ƚ���ѹ��
      preview_height = photo.getHeight() * preview_width / photo.getWidth();
    }
   
    if(preview_width == photo.getWidth() && preview_height == photo.getHeight()){
      //ͼ�񲻱�
      previewPath = origionalPath;
    }
    else{   
      //��������ͼ
      if(ImageUtils.isImage(extendName)){
        previewPath = ImageUtils.createPreviewImage(new FileInputStream(origionalPath),
            previewPath, preview_width, preview_height);
      }
      else{
        photo = null;
        return null;
View Full Code Here

    String path = uploadPath
        + StringUtils.replace(imgURL.substring(baseURI.length()), "/",
            File.separator);
    File f = new File(path);
    if(f.exists() && f.isFile())
      return new FileInputStream(f);
    return null;
  }
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

    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG,
                 "SSLTcpProxyService.createSocketFactory : keystoreFile=" + keystoreFile);
   
    KeyStore keystore = KeyStore.getInstance(ksType);
    keystore.load(new FileInputStream(keystoreFile),keyStorePass);
   
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(keystore,keyStorePass);
   
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
View Full Code Here

      if (dir.exists() && dir.isDirectory()) {
        File tfc = new File(dir, "TFC");
        if (tfc.exists()) {
          DataInputStream dis = null;
          try {
            dis = new DataInputStream(new FileInputStream(tfc));
            String tname = dis.readUTF();
            Class tclass = Class.forName(tname);
            transaction = (Transaction) tclass.newInstance();
          } catch (Exception exc) {
            logmon.log(BasicLevel.FATAL, getName() + ", can't instantiate transaction manager", exc);
View Full Code Here

                              FileMonitoringTimerTask.DEFAULT_MONITORING_CONFIG_PERIOD).longValue();
        String results = getProperty(FileMonitoringTimerTask.MONITORING_RESULT_PATH_PROPERTY,
                                     FileMonitoringTimerTask.DEFAULT_MONITORING_RESULT_PATH);
       
        Properties monitoringProps = new Properties();
        monitoringProps.load(new FileInputStream(file));
       
        fileMonitoringTimerTask = new FileMonitoringTimerTask(getTimer(), period, monitoringProps, results);
        if (fileMonitoringTimerTask != null) {
          try {
            MXWrapper.registerMBean(fileMonitoringTimerTask,
                                    "AgentServer", "server=" + getName() + ",cons=FileMonitoring");
          } catch (Exception exc) {
            if (logmon == null)
              logmon = Debug.getLogger(AgentServer.class.getName());
            logmon.log(BasicLevel.ERROR, getName() + " jmx failed", exc);
          }
        }
      }
    } catch (Exception exc) {
      logmon.log(BasicLevel.WARN, getName() + "Cannot read monitoring configuration file: " + config, exc);
    }
   
    config = getProperty(LogMonitoringTimerTask.MONITORING_CONFIG_PATH_PROPERTY,
                         LogMonitoringTimerTask.DEFAULT_MONITORING_CONFIG_PATH);
    try {
      // if "logMonitoring.props" file exists configure a FileMonitoringTimerTask.
      File file = new File(config);
      if (file.exists()) {
        long period = getLong(LogMonitoringTimerTask.MONITORING_CONFIG_PERIOD_PROPERTY,
                              LogMonitoringTimerTask.DEFAULT_MONITORING_CONFIG_PERIOD).longValue();       
        String logname = getProperty(LogMonitoringTimerTask.MONITORING_RESULT_LOGGER_PROPERTY,
                                     LogMonitoringTimerTask.DEFAULT_MONITORING_RESULT_LOGGER);
        Logger logger = Debug.getLogger(logname);
        int loglevel = getInteger(LogMonitoringTimerTask.MONITORING_RESULT_LEVEL_PROPERTY,
                                  LogMonitoringTimerTask.DEFAULT_MONITORING_RESULT_LEVEL).intValue();
        String logmsg = getProperty(LogMonitoringTimerTask.MONITORING_RESULT_MESSAGE_PROPERTY,
                                    LogMonitoringTimerTask.DEFAULT_MONITORING_RESULT_MESSAGE);
       
        Properties monitoringProps = new Properties();
        monitoringProps.load(new FileInputStream(file));
       
        logMonitoringTimerTask = new LogMonitoringTimerTask(getTimer(), period, monitoringProps,
                                                            logger, logmsg, loglevel);

        if (logMonitoringTimerTask != null) {
View Full Code Here

          return true;
        return false;
      }});
    if(mails!=null){
      for(int i=0;i<mailfiles.length&&i<max_count;i++){
        FileInputStream fis = null;
        try{
          fis = new FileInputStream(mailfiles[i]);
          mails.add(new MimeMessage(ssn, fis));
          if(ident!=null)
            ident.add(mailfiles[i].getPath());
          fis.close();
          fis = null;
          mailfiles[i].delete();
        }catch(MessagingException e){
          String newfile = mailfiles[i].getPath() + ERR;
          mailfiles[i].renameTo(new File(newfile));
          log.error("mail cache file destroy, rename to " + newfile, e);
        }catch(IOException e){
          String newfile = mailfiles[i].getPath() + ERR;
          mailfiles[i].renameTo(new File(newfile));
          log.error("IO Exception when read mail cache , rename to " + newfile, e);
        }finally{
          if(fis!=null)
            fis.close();
        }
      }
    }
    return mailfiles.length;   
  }
View Full Code Here


    Properties readProps(String fileName) throws IOException
    {
        Properties props;
        FileInputStream _stream = new FileInputStream(fileName);
        props=new Properties();
        props.load(_stream);
        return props;
    }
View Full Code Here

        file = new File(dir, name);
      } else {
        File parentDir = new File(dir, dirName);
        file = new File(parentDir, name);
      }
      FileInputStream fis = new FileInputStream(file);
      byte[] buf = new byte[(int) file.length()];
      for (int nb=0; nb<buf.length; ) {
        int ret = fis.read(buf, nb, buf.length-nb);
        if (ret == -1) throw new EOFException();
        nb += ret;
      }
      fis.close();

      return buf;
    } catch (FileNotFoundException exc) {
      return null;
    }
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.