Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:59:08+00:00 2026-05-26T02:59:08+00:00

In TCP i am receiving media stream from an IP camera as RAW. According

  • 0

In TCP i am receiving media stream from an IP camera as RAW. According to there advise, i need to write that as file. And then i can play it with media player such as VLC.

But when i write this to a file, and play with media players it never play corrupted.

After comparing the original file i see my Java writing it in wrong characters. And there sample file shows different. What or how do i fix such file writing issue, here is how i am writing it:

byte[] buf=new byte[1024];
int bytes_read = 0;
try {  
    bytes_read = sock.getInputStream().read(buf, 0, buf.length);                
    String data = new String(buf, 0, bytes_read);                   
    System.err.println("DATA: " +  bytes_read + " bytes, data=" +data);

        BufferedWriter out = new BufferedWriter(
            new FileWriter("capture.ogg", true));
        out.write(data);
        out.close();

} catch (IOException e) {
    e.printStackTrace(System.err);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:59:09+00:00Added an answer on May 26, 2026 at 2:59 am

    You’re doing it right… at least until the part where you turn your byte[] into a String:

    That step only really makes sense if your byte[] represents textual data in the first place! Which it doesn’t!

    Whenever you handle binary data or don’t actually care what the data represents you must avoid using String/Reader/Writer to handle that data. Instead do use byte[]/InputStream/OutputStream.

    Also, you must read from the socket in a loop, because nothing guarantees that you’ve read everything:

    byte[] buf=new byte[1024];
    int bytes_read;
    OutputStream out = new FileOutputStream("capture.ogg", true);
    InputStream in = sock.getInputStream();
    while ((bytes_read = in.read(buf)) != -1) {
        out.write(buf, 0, bytes_read);
    }
    out.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading data from a TCP/IP stream and am successfully receiving a byte
I have a TCP socket client receiving messages (data) from a server. messages are
In my program there is one thread (receiving thread) that is responsible for receiving
I need to use the tcp socket connection to get the data from a
I'm receiving data from tcp socket in binary view. In erlang shell i see:
I have one thread, that is receiving tcp packets and add each line to
There is the TCP URG flag that signa part of the TCP message as
I have problem with receiving an image over TCP socket [.net 4.0] Server: Socket
I have a TCP server application in which on receiving an incoming connection, I
TCP is stream-based, which means you send bytes without them necessarily being in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.