コード例 #1
0
ファイル: T9.java プロジェクト: esoros1/Programming-Stuff
  public static void main(String[] args) throws NumberFormatException, IOException {

    FileInputStream inFile = new FileInputStream(new File("C-small-practice.in"));
    DataInputStream in = new DataInputStream(inFile);
    FileOutputStream outFile = new FileOutputStream(new File("out.txt"));
    DataOutputStream out = new DataOutputStream(outFile);

    int cases = Integer.parseInt(in.readLine());

    t9Map = new HashMap<String, String>();
    fillMap();

    for (int i = 1; i <= cases; i++) {
      out.writeBytes("Case #" + i + ": ");
      String t9, t9last = "";

      String text = in.readLine();
      for (int j = 0; j < text.length(); j++) {

        t9 = t9Map.get(String.valueOf(text.charAt(j)));

        // do we need a break? (letters are on same button)
        if (j > 0 && (t9.charAt(0)) == t9last.charAt(0)) {
          out.writeBytes(" ");
        }

        out.writeBytes(t9);
        t9last = t9;
      }
      out.writeBytes("\n");
    }
  }
コード例 #2
0
ファイル: Graph.java プロジェクト: springer126/jDevelop
  private int Load_Nodes(DataInputStream inStream) {
    // need to open file and load data
    int node_id;
    int x_cor;
    int y_cor;
    // int n_nodes, n_edges, node_cnt, arrow_status;
    Node n;
    String line;
    String item1, item2, item3, item4;

    node_id = 0;
    x_cor = 0;
    y_cor = 0;
    // n_nodes = 0;
    // n_edges = 0;
    // arrow_status = -1;

    try {

      if ((line = inStream.readLine()) != null) {
        StringTokenizer Data = new StringTokenizer(line, " ");
        item1 = Data.nextToken();
        n_nodes = Integer.parseInt(item1);
        item2 = Data.nextToken();
        n_edges = Integer.parseInt(item2);
        item3 = Data.nextToken();
        arrow_status = Integer.parseInt(item3);
        // item4 = Data.nextToken();
        // type = Integer.parseInt( item4 );
        // graph = new GraphClass( n_nodes, n_edges, arrow_status );
        nodes = new Node[n_nodes];
        edges = new Edge[n_edges];

        // ???

        while ((this.Node_Cnt() < n_nodes) && ((line = inStream.readLine()) != null)) {
          Data = new StringTokenizer(line, " ");
          item1 = Data.nextToken();
          item2 = Data.nextToken();
          item3 = Data.nextToken();
          node_id = Integer.parseInt(item1);
          x_cor = Integer.parseInt(item2);
          y_cor = Integer.parseInt(item3);
          n = new Node(node_id, x_cor, y_cor);
          this.Add_Node(n);
        }
        if (n_nodes != 0) {
          source_node = nodes[0];
        }
      }
    } catch (IOException e) {
      System.err.println("error in file" + e.toString());
      System.exit(1);
    }
    return this.Node_Cnt();
  }
コード例 #3
0
ファイル: KepsFetcher.java プロジェクト: shuw/satmapper
 public boolean buildSatsFromKeps(Vector fileList) {
     
     Enumeration filelist = fileList.elements();
     while (filelist.hasMoreElements()) {
         String file = (String) filelist.nextElement();
         FileInputStream fis = null;
         DataInputStream dis = null;
         String lineRead = null;
         try {
             if (dir != null) {
                 fis = new FileInputStream(this.dir + file);
             } else {
                 fis = new FileInputStream(file);
             }
             dis = new DataInputStream(fis);
             System.out.println("Found file '" + dir + file + "': Loading keps");
             while (dis.available() > 0) {
                 lineRead = dis.readLine().trim();
                 if (lineRead.length() > 0) {
                     if (lineRead.length() > 20)
                         lineRead = lineRead.substring(0, 19);
                     Satellite sat = new Satellite(lineRead);
                     String firstLine = dis.readLine().trim();
                     if (firstLine.length() < 69) {
                         sat = null;
                     } else {
                         String secondLine = dis.readLine().trim();
                         if (secondLine.length() < 69) {
                             sat = null;
                         } else {
                             sat.setKeps(firstLine, secondLine);
                             
                             satVector.addElement(sat);
                         }
                     }
                 }
             }
         } catch (IOException _ex) {
             System.out.println("Sat data file '" + dir + file + "' not found");
             _ex.printStackTrace();
             return false;
         }
     }
     
     mapper.myData.allSats = satVector;
     
     return true;
     
 }
  public void initilize2() {
    int i;
    msg = s2.toCharArray();
    for (i = 0; i < s2.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.print(msg[i]);
      } catch (Exception e) {
        System.out.print("init 2 send" + e);
      }
    }

    try {

      while ((rs = dis.readLine()) != null) {
        // System.out.println(rs);
        if (rs.equals("OK")) {
          break;
        }
        if (rs.equals("ERROR")) {
          break;
        }
      }

    } catch (Exception e) {
      System.out.println("init 2 rec" + e);
    }
  }
コード例 #5
0
ファイル: TaskPersistence.java プロジェクト: mbhinder/floto
 @SuppressWarnings("deprecation")
 public void writeLogs(String taskId, OutputStream output) {
   try (FileInputStream input = new FileInputStream(getLogFile(taskId))) {
     DataInputStream dataInput = new DataInputStream(input);
     output.write("[\n".getBytes());
     byte[] buffer = new byte[4 * 1024];
     boolean needComma = false;
     try {
       while (true) {
         IOUtils.skip(input, 1);
         String line = dataInput.readLine();
         if (line == null || line.isEmpty()) {
           break;
         }
         int length = Integer.parseInt(line);
         if (length > buffer.length) {
           buffer = new byte[length];
         }
         IOUtils.readFully(input, buffer, 0, length);
         if (needComma) {
           output.write(",\n".getBytes());
         } else {
           needComma = true;
         }
         output.write(buffer, 0, length);
       }
     } catch (EOFException ignored) {
       // EOF reached
     }
     output.write("]\n".getBytes());
   } catch (Throwable throwable) {
     Throwables.propagate(throwable);
   }
 }
コード例 #6
0
ファイル: Graph.java プロジェクト: springer126/jDevelop
  private int Load_Edges(DataInputStream inStream, int num) {
    String line;
    String item1, item2, item3;
    int source_node;
    int dest_node;
    int value;
    int n_nodes, edge_cnt;
    // Node nodes_array[] = new Node[num]; // Wil
    Edge edge;
    n_nodes = num;
    Node nodes_array[];
    nodes_array = new Node[n_nodes];
    nodes_array = this.Node_Array(); // Wil
    edge_cnt = 0;

    try {
      while ((line = inStream.readLine()) != null) {
        StringTokenizer Data = new StringTokenizer(line, " ");
        item1 = Data.nextToken();
        item2 = Data.nextToken();
        item3 = Data.nextToken();
        source_node = Integer.parseInt(item1);
        dest_node = Integer.parseInt(item2);
        value = Integer.parseInt(item3);
        edge = new Edge(nodes_array[source_node - 1], nodes_array[dest_node - 1], value);
        this.Add_Edge(edge);
        edge_cnt++;
      }
      // inFile.close();
    } catch (IOException e) {
      System.err.println("Error in accessing URL: " + e.toString());
      System.exit(1);
    }
    return edge_cnt;
  }
コード例 #7
0
ファイル: HierarchyParams.java プロジェクト: nalabelle/tpmj
  public HierarchyParams(InputStream in) throws IOException {
    DataInputStream d = new DataInputStream(in);
    String s = null;
    StringBuffer buffer = new StringBuffer();
    do {
      s = d.readLine();
      if (s != null) buffer.append(s + "\n");
    } while (s != null);

    processFormattedData(buffer.toString());
  }
  public void read() {
    int i, j, k;
    String temp = "";
    String temp1 = "";

    msg = s3.toCharArray();
    for (i = 0; i < s3.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.println(msg[i]);
      } catch (Exception e) {
        System.out.print("read send" + e);
      }
    }
    try {
      while ((rs = dis.readLine()) != null) {
        temp += rs;
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
      }

      k = 0;
      StringTokenizer t = new StringTokenizer(temp, "\"");
      while (t.hasMoreTokens()) {
        temp1 = "" + t.nextToken().trim();
        k++;
        if (k == 7) {
          System.out.println(temp1);
          VoiceManager voiceManager = VoiceManager.getInstance();
          Voice helloVoice = voiceManager.getVoice("kevin");
          helloVoice.allocate();
          helloVoice.speak(temp1);
          helloVoice.deallocate();
        }
      }

    } catch (Exception e) {
      System.out.print("read rec" + e);
    }
  }
  public void delete() {
    int i;
    msg = s4.toCharArray();
    try {
      for (i = 0; i < s4.length(); i++) {
        dos.write(msg[i]);
        System.out.print(msg[i]);
      }

    } catch (Exception e) {
      System.out.print("del send" + e);
    }
    try {
      while ((rs = dis.readLine()) != null) {
        System.out.println(rs);
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
        if (rs.equals("+CMS ERROR: 321")) break;
      }
    } catch (Exception e) {
      System.out.print("del rec" + e);
    }
  }
コード例 #10
0
  @SuppressWarnings({"unchecked", "unchecked"})
  public static void main(String[] args) {
    Vector<String> v = new Vector<String>();
    DataInputStream inn;
    PrintStream out;
    Indexer w = new Indexer("myhash");
    try {
      FileInputStream indexSource = new FileInputStream("foo.txt");
      w.restore(indexSource);
      // w.disp();
    } catch (IOException e) {
      System.out.println(e.toString());
    }
    try {
      ServerSocket serv = new ServerSocket(4402);
      System.out.println(serv.getInetAddress());
      System.out.println("server started");
      while (true) {

        Socket client = serv.accept();
        System.out.println("Just connected to " + client.getRemoteSocketAddress());

        inn = new DataInputStream(client.getInputStream());

        System.out.println("client IP : " + client.getInetAddress());
        String ob = inn.readLine();
        System.out.println("ob is " + ob);
        String[] h = ob.split(" ");
        for (String i : h) {
          v.addElement(i.toLowerCase());
        }

        // Take care to use the right usage of the Index structure
        // hash - Dictionary Structure based on a Hashtable or HashMap from the Java collections
        // list - Dictionary Structure based on Linked List
        // myhash - Dictionary Structure based on a Hashtable implemented by the students
        // bst - Dictionary Structure based on a Binary Search Tree implemented by the students
        // avl - Dictionary Structure based on AVL Tree implemented by the students

        // System.out.println(perform);
        System.out.println("search request for : " + v.toString());

        // w.disp();

        ObjectIterator<vecnod> i = w.retrievePages(new ObjectIterator<String>(v));

        Vector<vecnod> no_dup_vec = new Vector<vecnod>();
        Vector<vecnod> dup_vec = new Vector<vecnod>();

        int argcount = v.size();

        v.clear();

        if (i == null) {
          System.out.println("Search complete.  0  hits found.");
          return;
        }
        vecnod temp = new vecnod();
        System.out.println("Search results:");

        while (i.hasNext()) {

          temp = i.next();
          String s = temp.url.toString();

          int bc = 1;
          for (int j = 0; j < s.length(); j++) {
            if (s.charAt(j) == '/') bc++;
          }
          temp.freq = temp.freq * 100 * 1 / (bc - 2); // ressigning rank
          System.out.println("URL is: " + s + " Rank is: " + temp.freq);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }