コード例 #1
0
ファイル: MSMWasHere.java プロジェクト: ayanch/DSLMON
  protected long copy(String inFileName, String outFileName) throws IOException {
    long res = 0;

    {
      InputStream in0 = new FileInputStream(inFileName);
      Reader r0 = new InputStreamReader(in0);
      BufferedReader r1 = new BufferedReader(r0, 8 * 1024);

      OutputStream out0 = new FileOutputStream(outFileName);
      CountOutputStream out1 = new CountOutputStream(out0);
      Writer w0 = new OutputStreamWriter(out1);
      BufferedWriter w1 = new BufferedWriter(w0, 8 * 1024);

      int lineCount = 0;

      boolean cont = true;
      while (cont) {
        String line = r1.readLine();
        if (line == null) {
          cont = false;
        } else {
          lineCount++;

          w1.write(line);
          //          w1.write('\n');  //yes, this is not a direct copy; CRLF-whatever may be
          // converted!
          w1.write("\r\n"); // yes, this is not a direct copy; CRLF-whatever may be converted!
        }
      }

      w1.flush();
      w1.close();

      // TODO: Close files - handle I/O exceptions!

      // System.out.println("Line count: "+lineCount);

      res = out1.getCount();
    }

    return res;
  }