package mybuffer1;
import java.io.*;
public class MyBuffer
{
private InputStream r;
private int count=0,pos=0;
byte[] buf=new byte[1024];
MyBuffer(InputStream r)
{
this.r=r;
}
public int MyRead() throws IOException
{
if(count==0)
{
if(count<0)
return -1;
count=r.read(buf);
pos=0;
byte bt=buf[pos];
pos++;
count--;
return bt&255;
}
else if(count>0)
{
byte bt = buf[pos];
pos++;
count--;
return bt & 0xff;
}
return -1;
}
public void MyClose()throws IOException
{
r.close();
}
}
package mybuffer1;
import java.io.*;
public class MyBufferDemo {
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
long start=System.currentTimeMillis();
Copy();
long end=System.currentTimeMillis();
System.out.println("time="+(end-start));
}
public static void Copy() throws IOException
{
MyBuffer mf=new MyBuffer(new FileInputStream("e:\\bbb.mp3"));
BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream("e:\\bb.mp3"));
int ch=0;
while((ch=mf.MyRead())!=-1)
fos.write(ch);
mf.MyClose();
fos.close();
}
} |
|