Package java.io

Examples of java.io.BufferedReader


   */
  public void loadRuleFile(String filename)
    throws IOException
  {
    InputStream is = new FileInputStream(filename);
    BufferedReader reader =
      new BufferedReader(new InputStreamReader(is));

    String line = "";
    int lineno=0;

    while (line != null) {
      line=reader.readLine();
      lineno++;

      if ((line != null) &&
    (! line.trim().equals("")) &&
    (! line.startsWith("#"))) {
View Full Code Here


        List<T> providers = new LinkedList<T>();
        String providerClassName = providerClass.getName();
        providerClassName = providerClassName.substring(providerClassName.indexOf('.')+1);
        URL servicesURL = loader.findResource("META-INF/services/" + providerClass.getName());
        if (servicesURL != null) {
            BufferedReader in
                = new BufferedReader(new InputStreamReader(servicesURL.openStream()));
            try {
                String className;
                while ((className = in.readLine()) != null) {
                    log.info("Loading the " + providerClassName + " implementation: " + className);
                    try {
                        Class<? extends T> clazz
                            = loader.loadClass(className).asSubclass(providerClass);
                        providers.add(clazz.newInstance());
                    } catch (ClassNotFoundException e) {
                        handleException("Unable to find the specified class on the path or " +
                            "in the jar file", e);
                    } catch (IllegalAccessException e) {
                        handleException("Unable to load the class from the jar", e);
                    } catch (InstantiationException e) {
                        handleException("Unable to instantiate the class specified", e);
                    }
                }
            } finally {
                in.close();
            }
        }
        return providers;
    }
View Full Code Here

          +" weka.classifiers.meta.CostSensitiveClassifier or"
          +" weka.classifiers.meta.MetaCost");

      Reader costReader = null;
      try {
        costReader = new BufferedReader(new FileReader(costFileName));
      } catch (Exception e) {
        throw new Exception("Can't open file " + e.getMessage() + '.');
      }
      try {
        // First try as a proper cost matrix format
        return new CostMatrix(costReader);
      } catch (Exception ex) {
        try {
          // Now try as the poxy old format :-)
          //System.err.println("Attempting to read old format cost file");
          try {
            costReader.close(); // Close the old one
            costReader = new BufferedReader(new FileReader(costFileName));
          } catch (Exception e) {
            throw new Exception("Can't open file " + e.getMessage() + '.');
          }
          CostMatrix costMatrix = new CostMatrix(numClasses);
          //System.err.println("Created default cost matrix");
View Full Code Here

        getPersonDao().detachAll();
        getFeatureDao().detachAll();
        getLocationDao().detachAll();
        getEventDao().detachAll();

        BufferedReader bReader = new BufferedReader(reader);

        updateStatus(10);
        try {
            //1. The first line defines the number of some data:
            String numberOf[] = bReader.readLine().split(" ");
            int noOfEvents = Integer.parseInt(numberOf[0]);
            int noOfLocations = Integer.parseInt(numberOf[1]);
            int noOfFeatures = Integer.parseInt(numberOf[2]);
            int noOfPersons = Integer.parseInt(numberOf[3]);

            // 2. Every line contains the capacity of one room
            for (int i = 0; i < noOfLocations; i++) {
                Location location = createLocation(Integer.parseInt(bReader.readLine()));
                location.putConstraint(newRasterConstraint());
//                EventSetConstraint esc = (EventSetConstraint) appCtx.getBean(ES_CONSTRAINT);
//                location.putConstraint(esc);
            }

            // initialize events
            for (int i = 0; i < noOfEvents; i++) {
                createEvent();
            }

            // initialize features
            for (int i = 0; i < noOfFeatures; i++) {
                createFeature();
            }

            updateStatus(30);
            double tmp = 10.0 / (noOfPersons + 1);
            // 3. 'noOfSubjects'-lines describes the choice of one person (student/event)
            Person currentPerson;
            for (int p = 0; p < noOfPersons; p++) {
                updateStatus(30 + (int) (p * tmp));

                currentPerson = createPerson();
                currentPerson.putConstraint(newRasterConstraint());

                for (Event event : getEventDao().getAll()) {
                    if ((Integer.parseInt(bReader.readLine()) > 0)) {
                        currentPerson.addEvent(event, true);
                    }
                }
            }

            updateStatus(40);
            // 4. Now 'noOfFeatures'-lines describes the features of one room (room/feature)
            for (Location currentLocation : getLocationDao().getAll()) {
                for (Feature feature : getFeatureDao().getAll()) {
                    if ((Integer.parseInt(bReader.readLine()) > 0)) {
                        currentLocation.addFeature(feature);
                    }
                }
            }

            updateStatus(50);
            // 5. 'noOfFeatures'-lines describes the features-requirements of one subject (event/feature)
            for (Event currentSubject : getEventDao().getAll()) {
                for (Feature feature : getFeatureDao().getAll()) {
                    if ((Integer.parseInt(bReader.readLine()) != 0)) {
                        currentSubject.addFeature(feature);
                    }
                }
            }

            updateStatus(60);
            // 6. 'noOfTimeSlots'-lines describes the valid assignments of one subject (event/timeslot)
            int noOfTimeSlots = poolSettings.getTimeslotsPerWeek();
            for (Event currentEvent : getEventDao().getAll()) {
                RasterConstraint rc = newRasterConstraint();
                currentEvent.putConstraint(rc);
                WeekRaster raster = rc.getRaster();
                for (int ts = 0; ts < noOfTimeSlots; ts++) {
                    //String s = reader.readLine(); sb.append(s);
                    if (Integer.parseInt(bReader.readLine()) != 0) {
                        raster.set(ts, RasterEnum.ALLOWED);
                    }
                }
            }

            updateStatus(70);
            // 7. 'noOfSubjects'-lines describes the 'follow/before'-matrix of one subject (event/event)
            for (Event firstEvent : getEventDao().getAll()) {
                for (Event secEvent : getEventDao().getAll()) {
                    int i = Integer.parseInt(bReader.readLine());
                    if (i == 1) {
                        // add the constraint to the both event
                        EventOrderConstraint firstConstraint = firstEvent.getConstraint(EventOrderConstraint.class);
                        if (firstConstraint == null) {
                            firstConstraint = new EventOrderConstraint(firstEvent);
                            firstEvent.putConstraint(firstConstraint);
                        }
                        firstConstraint.addFollow(secEvent);

                        EventOrderConstraint secConstraint = secEvent.getConstraint(EventOrderConstraint.class);
                        if (secConstraint == null) {
                            secConstraint = new EventOrderConstraint(secEvent);
                            secEvent.putConstraint(secConstraint);
                        }
                        secConstraint.addBefore(firstEvent);
                    } else if (i == -1) {
                        // We could check now the priviously added followers and beforers,
                        // but this is not possible because '-1' could occur the
                        // first time (instead of expected '1')
                    }
                }
            }

            updateStatus(80);
//            getMagicNumbersOfDataPool();

            String line = bReader.readLine();
            if (line != null) {
                logger.fatal("End of file should be reached. But content of line was:" + line);
                int counter = 0;
                while ((line = bReader.readLine()) != null) {
                    counter++;
                }
                logger.fatal("Further " + counter + " unprocessed lines detected");
            }
        } finally {
View Full Code Here

        conn = connURL.openConnection();
      }
     
      conn.setConnectTimeout(30000); // timeout after 30 seconds
     
      BufferedReader bi =
        new BufferedReader(new InputStreamReader(conn.getInputStream()));
     
      String n = bi.readLine();
      try {
        numPackages = Integer.parseInt(n);
      } catch (NumberFormatException ne) {
        System.err.println("[WekaPackageManager] problem parsing number " +
            "of packages from server.");
      }
      bi.close();

    } catch (Exception ex) {
      ex.printStackTrace();
    }
   
View Full Code Here

      conn = connURL.openConnection();
    }
   
    conn.setConnectTimeout(30000); // timeout after 30 seconds
   
    BufferedReader bi =
      new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String l = null;
    while ((l = bi.readLine()) != null) {
      result.put(l,l);
    }
    bi.close();
   
    } catch (Exception ex) {
      ex.printStackTrace();
      result = null;
    }
View Full Code Here

    if (m_OutputFilename)
      newInst = new double[3];
    else
      newInst = new double[2];       
    File txt = new File(directoryPath + File.separator + subdirPath + File.separator + files[j]);
    BufferedReader is;
    if (m_charSet == null || m_charSet.length() == 0) {
      is = new BufferedReader(new InputStreamReader(new FileInputStream(txt)));
    } else {
      is = new BufferedReader(new InputStreamReader(new FileInputStream(txt), m_charSet));
    }
    StringBuffer txtStr = new StringBuffer();
    int c;
    while ((c = is.read()) != -1) {
      txtStr.append((char) c);
    }
   
    newInst[0] = (double) data.attribute(0).addStringValue(txtStr.toString());
    if (m_OutputFilename)
      newInst[1] = (double) data.attribute(1).addStringValue(subdirPath + File.separator + files[j]);
    newInst[data.classIndex()] = (double) k;
    data.add(new DenseInstance(1.0, newInst));
          is.close();
  }
  catch (Exception e) {
    System.err.println("failed to convert file: " + directoryPath + File.separator + subdirPath + File.separator + files[j]);
  }
      }
View Full Code Here

    String costName = train.relationName() + CostMatrix.FILE_EXTENSION;
    File costFile = new File(getOnDemandDirectory(), costName);
    if (!costFile.exists()) {
      throw new Exception("On-demand cost file doesn't exist: " + costFile);
    }
    CostMatrix costMatrix = new CostMatrix(new BufferedReader(
    new FileReader(costFile)));
   
    Evaluation eval = new Evaluation(train, costMatrix);   
    m_Classifier = AbstractClassifier.makeCopy(m_Template);
   
View Full Code Here

  protected String postOnEndPoint(String postBody) throws MalformedURLException, IOException {
    HttpURLConnection connection = (HttpURLConnection) new URL(END_POINT).openConnection();
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setDoOutput(true);
    connection.getOutputStream().write(postBody.getBytes());
    BufferedReader bufReader = new BufferedReader(new InputStreamReader(connection.getResponseCode() < 300 ? connection.getInputStream() :
      connection.getErrorStream()));
    StringBuffer buf = new StringBuffer();
    String str = bufReader.readLine();
    while(str != null){
      buf.append(str);
      str = bufReader.readLine();
    }
    bufReader.close();
    connection.disconnect();
    return buf.toString();
  }
View Full Code Here

     *
     * @return the message
     */
    protected String receive() {
        try {
            return new BufferedReader(new InputStreamReader(System.in)).readLine();
        } catch (IOException e) {
            throw new RuntimeException("Error reading from input", e);
        }
    }
View Full Code Here

TOP

Related Classes of java.io.BufferedReader

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.