Ejemplo n.º 1
0
  ArrayList<String> readBlacklist(String blkDictionaryFilePath) {
    ArrayList<String> wordsBlacklist = new ArrayList<String>();
    String tempLine = null;
    BufferedReader blkReader = null;
    try {
      Reader reader = new FileReader(blkDictionaryFilePath);
      blkReader = new BufferedReader(reader);
      while ((tempLine = blkReader.readLine()) != null) {
        if (tempLine.trim().length() == 0) continue;
        String[] words = tempLine.split(" ");
        for (String word : words) {
          wordsBlacklist.add(word);
        }
      }
    } catch (Exception e) {
      println("Be careful : " + e.getMessage());
    }
    if (blkReader != null) {
      try {
        blkReader.close();
      } catch (Exception e) {

      }
    }

    return wordsBlacklist;
  }
Ejemplo n.º 2
0
 public String readTwitterFeed() {
   StringBuilder builder = new StringBuilder();
   HttpClient client = new DefaultHttpClient();
   HttpGet httpGet = new HttpGet("http:'//twitter.com/users/show/vogella.json");
   try {
     HttpResponse response = client.execute(httpGet);
     StatusLine statusLine = response.getStatusLine();
     int statusCode = statusLine.getStatusCode();
     if (statusCode == 200) {
       HttpEntity entity = response.getEntity();
       InputStream content = entity.getContent();
       BufferedReader reader = new BufferedReader(new InputStreamReader(content));
       String line;
       while ((line = reader.readline()) != null) {
         builder.append(line);
       }
     } else {
       Log.e(MainActivity2.class.toString(), "Failed to download file");
     }
   } catch (ClientProtocolExpcetion e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return builder.toString();
 }
Ejemplo n.º 3
0
  @SuppressWarnings("empty-statement")
  public void read(InputStream is) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF8"));

    String line = null;

    String currentJar = null;

    Vector<String> jars = new Vector<>();

    while ((line = br.readLine()) != null && !line.endsWith(".jar")) ;
    for (; line != null; line = br.readLine()) {
      if (line.length() == 0) {
        continue;
      }

      if (line.endsWith(".jar")) {
        currentJar = line;

        jars.add(currentJar);
      } else {
        String name = line;

        addMapping(name, currentJar);
      }
    }

    jarFiles = jars.toArray(new String[jars.size()]);
  }
Ejemplo n.º 4
0
	Public void accept() throws IOException{
	
		InputStreamReader ir = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(ir);
		
		System.out.println("enter the name of person");
		name = br.readLine();
		System.out.println("enter the age of person");
		age = br.readLine();
		
	}
Ejemplo n.º 5
0
  public void handleInitialCampaignMessage(InitialCampaignMessage campaignMessage) {
    System.out.println(campaignMessage.toString());
    /**
     * ***********************************Open and read the camplog
     * file******************************************************
     */
    String str = null;
    try {
      //  int count = 0;
      FileReader file = new FileReader("camLog.txt");
      BufferedReader reader = new BufferedReader(file);

      str = reader.readLine();

      campaignData.count = Integer.parseInt(str);

    } catch (IOException e) {

    }

    System.out.println("********^^^^^^^^^^^^^^^^^^^^******************" + campaignData.count);

    /**
     * ***********************************end
     * file****************************************************************************
     */
    w.day = 0;

    initialCampaignMessage = campaignMessage;
    demandAgentAddress = campaignMessage.getDemandAgentAddress();
    adxAgentAddress = campaignMessage.getAdxAgentAddress();

    CampaignData campaignData = new CampaignData(initialCampaignMessage);
    campaignData.setBudget(initialCampaignMessage.getBudgetMillis() / 1000.0);
    d.currCampaign = campaignData;
    initTotalPopularity(campaignData);
    genCampaignQueries(campaignData);

    /*
     * The initial campaign is already allocated to our agent so we add it
     * to our allocated-campaigns list.
     */
    System.out.println("Day " + w.day + ": Allocated campaign - " + campaignData);
    d.campaigns.put(initialCampaignMessage.getId(), campaignData);
    for (int i = 0; i < 60; i++) {
      d.campTrack.add(new ArrayList<Integer>());
      d.otherCampTrack.add(new ArrayList<Integer>());
    }
    for (int i = (int) d.currCampaign.dayStart; i <= (int) d.currCampaign.dayEnd; i++) {
      d.campTrack.get(i).add(d.currCampaign.id);
    }
  }
Ejemplo n.º 6
0
  public boolean[] parse(String s, boolean[] input) {
    // set input
    this.input = input;
    this.error = false;

    String log = new String();
    for (int i = 0; i < input.length; i++) {
      log += i + ":" + String.valueOf(input[i]) + "-";
    }
    GWT.log("Input: " + log);

    HashMap<Integer, Conjunction> map = new HashMap<Integer, Conjunction>();
    int i = 0;

    BufferedReader reader = new BufferedReader(new StringReader(s));

    try {
      String line;
      while ((line = reader.readLine()) != null) {
        String tokens[] = line.split(" ");
        for (int t = 0; t < tokens.length; t++) {
          String operator = tokens[t];
          t++;
          if (operator.equals("=")) {
            conjunction(map);
            writeValue(tokens[t++], tokens[t++], VKE);
          } else if (operator.equals("R")) {
            writeValue(tokens[t++], tokens[t++], false);
          } else if (operator.equals("S")) {
            writeValue(tokens[t++], tokens[t++], true);
          } else {
            map.put(
                i,
                new Conjunction(readValue(tokens[t++], tokens[t++]), Operation.valueOf(operator)));
            i++;
          }
        }
      }

    } catch (Exception e) {
      this.error = true;
    }

    // second to last field is error flag
    this.output[this.output.length - 2] = this.error;
    // last field in output is VKE
    this.output[this.output.length - 1] = this.VKE;
    return this.output;
  }
Ejemplo n.º 7
0
 // go to end of file
 BufferedReader readEndOfFile(String logFilePath) {
   BufferedReader logReader = null;
   String line = null;
   String tempLine = null;
   try {
     Reader reader = new FileReader(logFilePath);
     logReader = new BufferedReader(reader);
     while ((tempLine = logReader.readLine()) != null) {
       line = tempLine;
     }
   } catch (Exception e) {
     println("Error while reading Plover log file: " + e.getMessage());
   }
   return logReader;
 }
Ejemplo n.º 8
0
 // get next word
 Stroke getNextStroke(BufferedReader logReader) {
   Stroke stroke = new Stroke();
   String line = null;
   try {
     line = logReader.readLine();
     int indexOfTransl = -1;
     if (line != null) indexOfTransl = line.indexOf("Translation");
     if (line != null && indexOfTransl > -1) {
       boolean isMultipleWorld = false;
       int indexOfLast = 1 + line.indexOf(",) : ");
       if (indexOfLast < 1) {
         isMultipleWorld = true;
         indexOfLast = line.indexOf(" : ");
       }
       if (indexOfTransl == 24) {
         stroke.isDelete = false;
       } else {
         stroke.isDelete = true;
       }
       stroke.stroke = getStroke(line, indexOfTransl + 14, indexOfLast - 2);
       stroke.word = line.substring(indexOfLast + (isMultipleWorld ? 2 : 3), line.length() - 1);
       return stroke;
     } else {
       return null;
     }
   } catch (Exception e) {
     println("Error while reading stroke from Plover log file: " + e.getMessage());
   }
   return null;
 }
Ejemplo n.º 9
0
  /**
   * POST pData to pUrl
   *
   * @return the response Customized for sending pngs with name="spectrum[photo]" ... possibly lead
   *     if we switch to ImageIO: http://pastebin.com/f6783c437
   */
  public String postData(URL pUrl, byte[] pData, String filename) {
    // http://wiki.processing.org/w/Saving_files_to_a_web_server
    try {
      URLConnection c = pUrl.openConnection();
      c.setDoOutput(true);
      c.setDoInput(true);
      c.setUseCaches(false);

      // set request headers
      final String boundary = "AXi93A";
      c.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);

      // open a stream which can write to the url
      DataOutputStream dstream = new DataOutputStream(c.getOutputStream());

      // write content to the server, begin with the tag that says a content element is comming
      dstream.writeBytes("--" + boundary + "\r\n");

      // describe the content
      // dstream.writeBytes("Content-Disposition: form-data; name=\"data\"; filename=\"whatever\"
      // \r\nContent-Type: text/json\r\nContent-Transfer-Encoding: binary\r\n\r\n");
      dstream.writeBytes(
          "Content-Disposition: form-data; name=\"photo\"; filename=\""
              + filename
              + "\" \r\nContent-Type: image/png\r\nContent-Transfer-Encoding: binary\r\n\r\n");
      dstream.write(pData, 0, pData.length);

      // close the multipart form request
      dstream.writeBytes("\r\n--" + boundary + "--\r\n\r\n");
      dstream.flush();
      dstream.close();

      // read the output from the URL
      BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
      StringBuilder sb = new StringBuilder(in.readLine());
      String s = in.readLine();
      while (s != null) {
        s = in.readLine();
        sb.append(s);
      }
      return sb.toString();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
 /**
  * Sets a mark position in this reader. The parameter {@code readlimit} indicates how many
  * characters can be read before the mark is invalidated. Sending {@code reset()} will reposition
  * this reader back to the marked position, provided that {@code readlimit} has not been
  * surpassed. The line number associated with this marked position is also stored so that it can
  * be restored when {@code reset()} is called.
  *
  * @param readlimit the number of characters that can be read from this stream before the mark is
  *     invalidated.
  * @throws IOException if an error occurs while setting the mark in this reader.
  * @see #markSupported()
  * @see #reset()
  */
 @Override
 public void mark(int readlimit) throws IOException {
   synchronized (lock) {
     super.mark(readlimit);
     markedLineNumber = lineNumber;
     markedLastWasCR = lastWasCR;
   }
 }
 /**
  * Resets this reader to the last marked location. It also resets the line count to what is was
  * when this reader was marked. This implementation resets the source reader.
  *
  * @throws IOException if this reader is already closed, no mark has been set or the mark is no
  *     longer valid because more than {@code readlimit} bytes have been read since setting the
  *     mark.
  * @see #mark(int)
  * @see #markSupported()
  */
 @Override
 public void reset() throws IOException {
   synchronized (lock) {
     super.reset();
     lineNumber = markedLineNumber;
     lastWasCR = markedLastWasCR;
   }
 }
Ejemplo n.º 12
0
  public static void main(String[] args) throws Exception {
    // Connect to Taxi
    URL taxi =
        new URL("http://taxonomy.yellowpages.com/api/releases/current/elements?app=taxi&view=true");
    URLConnection tc = taxi.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
    in.close();

    ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
    User user = mapper.readValue(new File("user.json"), User.class);
    User.Name name = user.getName();
    System.out.println(" NAME =" + name.getFirst());
    String ver = new Boolean(user.isVerified()).toString();
    System.out.println(" isVerified =" + ver);
  }
Ejemplo n.º 13
0
 private void dumpStream(InputStream stream) throws IOException {
   BufferedReader in = new BufferedReader(new InputStreamReader(stream));
   int i;
   try {
     while ((i = in.read()) != -1) {
       MessageOutput.printDirect((char) i); // Special case: use
       //   printDirect()
     }
   } catch (IOException ex) {
     String s = ex.getMessage();
     if (!s.startsWith("Bad file number")) {
       throw ex;
     }
     // else we got a Bad file number IOException which just means
     // that the debuggee has gone away.  We'll just treat it the
     // same as if we got an EOF.
   }
 }
Ejemplo n.º 14
0
 public String next() {
   while (tokenizer == null || !tokenizer.hasMoreTokens()) {
     try {
       tokenizer = new StringTokenizer(reader.readLine());
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   return tokenizer.nextToken();
 }
Ejemplo n.º 15
0
 protected void readList() {
     Path path = Paths.get(fileName);
     try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
         String line;
         while ((line = reader.readLine()) != null) {
             String[] data = line.split(",");
             int id = Integer.parseInt(data[0]);
             String Member = data[1];
             String Exercise = data[2];
             String Date = data[3];
             double Time = Double.parseDouble(data[4]);
             String Comments = data[5];
             Exercise member = new Exercise(id, Member, Exercise, Date, Time, Comments);
             myList.add(member);
         }
     } catch (IOException ioe) {
         System.out.println("Read file error with " + ioe.getMessage());
     }
 }
Ejemplo n.º 16
0
 public String next() {
   try {
     if (strtok == null || strtok.hasMoreTokens() == false) {
       strtok = new StringTokenizer(in.readLine());
     }
     return strtok.nextToken();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 17
0
 public String nextLine() {
   try {
     if (strtok == null) {
       return in.readLine();
     } else {
       String ret = (strtok.hasMoreTokens()) ? strtok.nextToken("\n") : "";
       strtok = null;
       return ret;
     }
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 18
0
 Object try_with_resource() {
   String path = ""; // compliant
   try (BufferedReader br = new BufferedReader(new FileReader(path))) {
     br.readLine();
   }
 }
Ejemplo n.º 19
0
  public ArrayList<Word> readDictionary(
      String lesDictionaryFilePath, String chdDictionaryFilePath, boolean debug) {
    String tempLine = null;
    BufferedReader lesReader = null;
    BufferedReader chdReader = null;
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> strokes = new ArrayList<String>();
    ArrayList<Word> dictionary = new ArrayList<Word>();

    try {
      Reader reader = new FileReader(lesDictionaryFilePath);
      lesReader = new BufferedReader(reader);
      while ((tempLine = lesReader.readLine()) != null) {
        if (tempLine.length() != 0 && tempLine.charAt(0) == '<' || tempLine.trim().length() == 0)
          continue;
        String[] newWords = tempLine.split(" ");
        for (String word : newWords) {
          words.add(word);
        }
      }
    } catch (Exception e) {
      println("Error : " + e.getMessage());
    }
    if (lesReader != null) {
      try {
        lesReader.close();
      } catch (Exception e) {

      }
    }

    try {
      Reader reader = new FileReader(chdDictionaryFilePath);
      chdReader = new BufferedReader(reader);
      while ((tempLine = chdReader.readLine()) != null) {
        if (tempLine.length() != 0 && tempLine.charAt(0) == '<' || tempLine.trim().length() == 0)
          continue;
        String[] newStrokes = tempLine.split(" ");
        for (String stroke : newStrokes) {
          strokes.add(stroke);
        }
      }
    } catch (Exception e) {
      println("Error Reading: " + e.getMessage());
    }
    if (chdReader != null) {
      try {
        chdReader.close();
      } catch (Exception e) {

      }
    }

    if (words != null && strokes != null)
      for (int i = 0; i < words.size(); i++) {
        Word word = new Word();
        word.word = words.get(i);
        word.stroke = strokes.get(i);
        dictionary.add(word);
      }

    if (debug) {
      println(
          "Current lesson contains " + words.size() + " words and " + strokes.size() + " chords.");
    }

    return dictionary;
  }