예제 #1
0
  public void close() {
    if (closed) {
      return;
    }
    closed = true;

    /* close the underlying connection if,
     * a) the streams not set up yet, no response can be sent, or
     * b) if the wrapper output stream is not set up, or
     * c) if the close of the input/outpu stream fails
     */
    try {
      if (uis_orig == null || uos == null) {
        connection.close();
        return;
      }
      if (!uos_orig.isWrapped()) {
        connection.close();
        return;
      }
      if (!uis_orig.isClosed()) {
        uis_orig.close();
      }
      uos.close();
    } catch (IOException e) {
      connection.close();
    }
  }
예제 #2
0
  public static void copyFile(String filenameIn, String filenameOut, boolean buffer)
      throws IOException {
    long lenIn = new File(filenameIn).length();
    if (debug) System.out.println("read " + filenameIn + " len = " + lenIn);

    InputStream in = new FileInputStream(filenameIn);
    if (buffer) new BufferedInputStream(in, 10000);

    OutputStream out = new FileOutputStream(filenameOut);
    if (buffer) out = new BufferedOutputStream(out, 1000);

    long start = System.currentTimeMillis();
    IO.copyB(in, out, 10000);
    out.flush();
    double took = .001 * (System.currentTimeMillis() - start);

    out.close();
    in.close();

    long lenOut = new File(filenameOut).length();
    if (debug) System.out.println(" write file= " + filenameOut + " len = " + lenOut);

    double rate = lenIn / took / (1000 * 1000);
    String name = buffer ? "buffer" : "no buffer";
    System.out.println(" copy (" + name + ") took = " + took + " sec; rate = " + rate + "Mb/sec");
  }
예제 #3
0
파일: LibRt.java 프로젝트: yamila87/rt_src
 public static int pipe_stream(InputStream is, OutputStream os, boolean wantsKeepOpen)
     throws IOException { // U: copia de un stream al otro
   int cnt = 0;
   int n;
   byte[] buffer = new byte[BUFF_SZ];
   while ((n = is.read(buffer)) > -1) {
     cnt += n;
     os.write(buffer, 0, n);
   }
   if (!wantsKeepOpen) {
     is.close();
     os.close();
   }
   return cnt;
 }
예제 #4
0
 public void close() throws IOException {
   checkWrap();
   wrapped.close();
 }
예제 #5
0
파일: LibRt.java 프로젝트: yamila87/rt_src
 public static void set_stream(OutputStream os, String data, String encoding) throws IOException {
   os.write(data.getBytes(encoding));
   os.close();
 }