Exemplo n.º 1
0
 /**
  * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  *
  * @param request servlet request
  * @param response servlet response
  * @throws ServletException if a servlet-specific error occurs
  * @throws IOException if an I/O error occurs
  */
 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   response.setContentType("text/xml;charset=UTF-8");
   PrintWriter out = response.getWriter();
   try {
     // get exiting file, and output, looking for where to insert owners.
     BufferedReader in =
         new BufferedReader(
             new InputStreamReader(
                 this.getServletContext()
                     .getResourceAsStream(
                         "/WEB-INF/classes/gpt/search/browse/browse-catalog.xml")));
     log.fine("in: " + in.toString());
     String rec = null;
     while ((rec = in.readLine()) != null) {
       if (rec.contains("InsertOwnersHere")) {
         outputOwners(out);
       } else {
         out.println(rec);
       }
     }
   } finally {
     out.close();
   }
 }
Exemplo n.º 2
0
  public static Integer findFibonacci(int fibonacciNumber, String path) {

    try {
      BufferedReader in = new BufferedReader(new FileReader(path));
      in.toString();
      // formula of Jacques Philippe Marie Binet
      double fibonacci =
          (Math.pow(((1 + Math.sqrt(5)) / 2), fibonacciNumber)
                  - Math.pow(((1 - Math.sqrt(5)) / 2), fibonacciNumber))
              / Math.sqrt(5);
      String fibonacciToString =
          String.valueOf(fibonacci).substring(0, String.valueOf(fibonacci).indexOf("."));

    } catch (IOException e) {

    }
    //        return Integer.valueOf(fibonacciToString);
    return 0;
  }
Exemplo n.º 3
0
  // 得到页面的内容,返回值删掉了回车,传出参数未删除回车
  public static StringBuffer getPageBufferFromWeb2(String url, StringBuffer outBuffer) {
    StringBuffer sb = new StringBuffer();
    try {
      URL my_url = new URL(url);
      BufferedReader br = new BufferedReader(new InputStreamReader(my_url.openStream()));

      String strTemp = "";
      while (null != (strTemp = br.readLine())) {
        sb.append(strTemp);
        if (null != outBuffer) outBuffer.append(strTemp + "\r\n");
      }
      System.out.println("get page successful form " + url);
      if (null != outBuffer) outBuffer.append(br.toString());
    } catch (Exception ex) {
      // ex.printStackTrace();
      System.err.println("page not found: " + url);
    }

    return sb;
  }
Exemplo n.º 4
0
  public Object obterJson(Class<?> classe) {

    Object json = null;
    try {

      HttpEntity httpEntity = resposta.getEntity();
      if (httpEntity != null) {

        Gson gson = new GsonBuilder().create();
        InputStream httpEntityContent = httpEntity.getContent();
        BufferedReader in = new BufferedReader(new InputStreamReader(httpEntityContent));
        json = gson.fromJson(in, classe);
        Log.d("erro", in.toString());
        in.close();
        return json;
      }
    } catch (ClientProtocolException e) {
      Log.d("ClientProtocolException: ", e.toString());
    } catch (IOException e) {
      Log.d("IOException: ", e.toString());
    }
    return json;
  }
Exemplo n.º 5
0
  private void loadobject(BufferedReader br, String pathtoimages) {
    int linecounter = 0;
    try {

      String newline;
      boolean firstpass = true;
      mtl matset = new mtl();
      int mtlcounter = 0;

      while (((newline = br.readLine()) != null)) {
        linecounter++;
        newline = newline.trim();
        if (newline.length() > 0) {
          if (newline.charAt(0) == 'n' && newline.charAt(1) == 'e' && newline.charAt(2) == 'w') {
            if (firstpass) {
              firstpass = false;
            } else {
              Materials.add(matset);
              matset = new mtl();
            }
            String[] coordstext = new String[2];
            coordstext = newline.split("\\s+");
            matset.name = coordstext[1];
            matset.mtlnum = mtlcounter;
            mtlcounter++;
          } else if (newline.charAt(0) == 'K' && newline.charAt(1) == 'a') {
            float[] coords = new float[3];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            matset.Ka = coords;
          } else if (newline.charAt(0) == 'K' && newline.charAt(1) == 'd') {
            float[] coords = new float[3];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            matset.Kd = coords;
          } else if (newline.charAt(0) == 'K' && newline.charAt(1) == 's') {
            float[] coords = new float[3];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            matset.Ks = coords;
          } else if (newline.charAt(0) == 'd') {
            String[] coordstext = newline.split("\\s+");
            matset.d = Float.valueOf(coordstext[1]).floatValue();
          } else if (newline.contains("map_Ka")) {
            String texture = newline.replace("map_Ka ", "");
            while (texture.startsWith(" ")) texture = texture.replaceFirst(" ", "");
            if (texture != null) matset.map_Ka = texture;
          } else if (newline.contains("map_Kd")) {
            String texture = newline.replace("map_Kd ", "");
            while (texture.startsWith(" ")) texture = texture.replaceFirst(" ", "");
            if (texture != null) matset.map_Kd = texture;
          } else if (newline.contains("map_d")) {
            String texture = newline.replace("map_d ", "");
            while (texture.startsWith(" ")) texture = texture.replaceFirst(" ", "");
            if (texture != null) matset.map_d = texture;
          }
        }
      }
      Materials.add(matset);

    } catch (IOException e) {
      System.out.println("Failed to read file: " + br.toString());
      e.printStackTrace();
    } catch (NumberFormatException e) {
      System.out.println(
          "Malformed MTL (on line "
              + linecounter
              + "): "
              + br.toString()
              + "\r \r"
              + e.getMessage());
    } catch (StringIndexOutOfBoundsException e) {
      System.out.println(
          "Malformed MTL (on line "
              + linecounter
              + "): "
              + br.toString()
              + "\r \r"
              + e.getMessage());
    }
  }
Exemplo n.º 6
0
  private void loadobject(BufferedReader br) {
    int linecounter = 0;
    try {

      String newline;
      boolean firstpass = true;

      while (((newline = br.readLine()) != null)) {
        linecounter++;
        newline = newline.trim();
        if (newline.length() > 0) {
          if (newline.charAt(0) == 'v' && newline.charAt(1) == ' ') {
            float[] coords = new float[4];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            //// check for farpoints ////
            if (firstpass) {
              rightpoint = coords[0];
              leftpoint = coords[0];
              toppoint = coords[1];
              bottompoint = coords[1];
              nearpoint = coords[2];
              farpoint = coords[2];
              firstpass = false;
            }
            if (coords[0] > rightpoint) {
              rightpoint = coords[0];
            }
            if (coords[0] < leftpoint) {
              leftpoint = coords[0];
            }
            if (coords[1] > toppoint) {
              toppoint = coords[1];
            }
            if (coords[1] < bottompoint) {
              bottompoint = coords[1];
            }
            if (coords[2] > nearpoint) {
              nearpoint = coords[2];
            }
            if (coords[2] < farpoint) {
              farpoint = coords[2];
            }
            /////////////////////////////
            vertexsets.add(coords);
          }
          if (newline.charAt(0) == 'v' && newline.charAt(1) == 't') {
            float[] coords = new float[4];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            vertexsetstexs.add(coords);
          }
          if (newline.charAt(0) == 'v' && newline.charAt(1) == 'n') {
            float[] coords = new float[4];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            vertexsetsnorms.add(coords);
          }
          if (newline.charAt(0) == 'f' && newline.charAt(1) == ' ') {
            String[] coordstext = newline.split("\\s+");
            int[] v = new int[coordstext.length - 1]; // TODO magic
            int[] vt = new int[coordstext.length - 1];
            int[] vn = new int[coordstext.length - 1];

            for (int i = 1; i < coordstext.length; i++) {
              String fixstring = coordstext[i].replaceAll("//", "/0/");
              String[] tempstring = fixstring.split("/");
              v[i - 1] = Integer.valueOf(tempstring[0]).intValue(); // TODO magic Byte.decode

              if (tempstring.length > 1) {
                vt[i - 1] = Integer.valueOf(tempstring[1]).intValue();
              } else {
                vt[i - 1] = 0;
              }
              if (tempstring.length > 2) {
                vn[i - 1] = Integer.valueOf(tempstring[2]).intValue();
              } else {
                vn[i - 1] = 0;
              }
            }
            faces.add(v);
            facestexs.add(vt);
            facesnorms.add(vn);
          }
        }
      }

    } catch (IOException e) {
      System.out.println("Failed to read file: " + br.toString());
      // System.exit(0);
    } catch (NumberFormatException e) {
      System.out.println(
          "Malformed OBJ (on line "
              + linecounter
              + "): "
              + br.toString()
              + "\r \r"
              + e.getMessage());
      // System.exit(0);
    }
  }
Exemplo n.º 7
0
  public void updateHistory(IStockTimeSeries stock) {
    LOGGER.setLevel(Level.INFO);
    String inputLine;
    StringBuffer url = new StringBuffer(SERVERSTART);
    url.append(stock.getSymbol());
    url.append(SERVEREND);

    ReadStockFromWeb web = new ReadStockFromWeb();
    web.setUrl(url.toString());
    BufferedReader response = null;
    try {
      response = web.read();
    } catch (HttpException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    // Each line looks like the following
    // Stock symbol; Last Course; Time ; Date; Change; Open Course; Low;
    // High; Volume
    // BAS.DE;98,93;17:35;13/07/2007;+1,82;99,00;99,62;98,02;7100218
    LOGGER.info(response.toString());

    try {
      while ((inputLine = response.readLine()) != null) {
        LOGGER.info(inputLine);
        // item[0] Stock Symbol
        // item[1] Last course
        // item[2] Time
        // item[3] Date
        // item[4] Increase / Decrease
        // item[5] Opening value
        // item[6] Lowest Value
        // item[7] Highest Value
        // item[8] Volume

        String[] item = inputLine.split(";");
        int i = 0;
        for (String string : item) {
          LOGGER.info("Value number " + i + " " + string);
          i++;
        }

        // For now I ignore the time
        Date date;
        try {
          date = new SimpleDateFormat("dd/MM/yyyy").parse(item[3]);
        } catch (ParseException e) {
          throw new RuntimeException(e);
        }
        // For now I ignore the change
        Double change = 0.0;
        System.out.println(item[4].substring(0, 1));
        System.out.println("+");
        System.out.println(item[4].substring(1));
        String s = item[4].substring(0, 1);
        if (s.equalsIgnoreCase("+")) {
          change = convertStringToDouble(item[4].substring(1));
        }

        if ((item[4].substring(1)).equalsIgnoreCase("-")) {
          change = (-1) * convertStringToDouble(item[4].substring(1));
        }

        Double open = convertStringToDouble(item[5]);
        Double low = convertStringToDouble(item[6]);
        Double high = convertStringToDouble(item[7]);
        // int volume;
        int volume = (Integer.parseInt(item[8].trim()));

        System.out.println(date);
        System.out.println(change);
        System.out.println(open);
        System.out.println(low);
        System.out.println(high);
        System.out.println(volume);
      }
    } catch (NumberFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      response.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }