import java.io.*;

public class M {

public static void main(String[] args) throws FileNotFoundException {

StopWatch stopWatch = new StopWatch();
int bufferSize = 8192;

String filename1 = "/Users/paul/Downloads/star1.zip";
FileInputStream fileInputStream = new FileInputStream(new File(filename1));
FileOutputStream fileOutputStream = new FileOutputStream(new File(filename1 + ".copy"));

String filename3 = "/Users/paul/Downloads/star2.zip";
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(new File(filename3)), bufferSize);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(filename3 + ".copy")));

// 실제론 왜 이게 더 빠름?
byte[] buffer = new byte[bufferSize];
try {
stopWatch.start();

while (true) {
if (fileInputStream.read(buffer) == -1) break;
fileOutputStream.write(buffer);
}
fileInputStream.close();
fileInputStream.close();

stopWatch.stop();
System.out.println(stopWatch);
} catch(IOException e) {}

// 이게 더 빠르다며
try {
stopWatch.start();

int data;
int readCount = 0;
byte[] buf = new byte[bufferSize];
while (true) {
// data = bufferedInputStream.read(); 이렇게 하면 bufferedInputStream이 훨씬 느리
data = bufferedInputStream.read(buf, 0, buf.length); // 이렇게 하면 둘다 속도 동일함
if (data == -1) break;
// bufferedOutputStream.write(data);
bufferedOutputStream.write(buf);
readCount++;
}
bufferedInputStream.close();
bufferedOutputStream.close();

stopWatch.stop();
System.out.println(stopWatch);

System.out.println(readCount);
} catch (IOException e) {}


}
}

class StopWatch {
private long start;
private long end;

public void start() {
start = System.currentTimeMillis();
}

public void stop() {
end = System.currentTimeMillis();
}

public long getTime() {
return end - start;
}

public String toString() {
return String.valueOf(getTime());
}
}