Byte stream copying MP3 files (with buffer)

Source: Internet
Author: User
// Custom Buffer

Import java. Io .*;


Class mybufferedinputstream
{
Private byte [] Buf = new byte [1, 1024];

Private inputstream in;

Private int Pos = 0, Count = 0;

Mybufferedinputstream (inputstream in ){
This. In = in;
}

/*
Read one byte at a time from the buffer byte array.
*/
Public int myread (){
// Read hard disk data through the in object and store the data in Buf
If (COUNT = 0 ){
Count = in. Read (BUF );
If (count <0)
Return-1;
Pos = 0;
Byte B = Buf [POS];
Count --;
Pos ++;
Return B;
} Else if (count> 0 ){
Byte B = Buf [POS];
Count --;
Pos ++;
Return B;
}
Return-1;
}

Public void myclose (){
In. Close ();
}

}

 

Call Buffer:

Import Java. io. *; Class copymp3 {public static void main (string [] ARGs) throws exception {long start = system. currenttimemillis (); copy_1 (); long end = system. currenttimemillis (); system. out. println (end-Start);} // copy public static void copy_2 () throws exception {bufferedinputstream bufd = new bufferedinputstream (New fileinputstream ("C: \ 1.mp3 "); bufferedoutputstream bufos = new buff Eredoutputstream (New fileoutputstream ("C: \ 2.mp3"); int by = 0; while (by = bufcm. myread ())! =-1) {bufos. Write (by);} bufos. Close (); bufcm. myclose ();}}

 

-----------------------

Problem:

The copied file contains 0 bytes.

0000-0001

1111-1110

1111-1111

 

Byte:-1 ---> INT:-1

He will add 1 to the front. In order to add 0 to the front, & 255 is required.

 

Minimum four places & 15

1 1 1 1

Minimum 8 bits & 255

1111 1111

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.