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

  • Home
  • SEARCH
  • 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 6678235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:13:06+00:00 2026-05-26T04:13:06+00:00

this is a followup on my former question here . The resulting file which

  • 0

this is a followup on my former question here.

The resulting file which should be a wave file is by far too lage when I am using a byte array like in the example with size 1024 * 32.
If I am using a smaller size like only 32 bytes or even do a single byte like

fstr.write(this.stream.read());

it works perfectly.

Following code:

import java.io.*;

class ErrorThread extends Thread {
    InputStream stream = null;

    public ErrorThread(InputStream stream) {
    this.stream = stream;
    }

    public void run() {
    try {
        byte[] buf = new byte[32 * 1024];
        int nRead = 0;
        while ((nRead = this.stream.read()) != -1) {

        }
        this.stream.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    }
}

class InputThread extends Thread {
    InputStream stream = null;

    public InputThread(InputStream stream) {
    this.stream = stream;
    }

    public void run() {
    try {
        FileOutputStream fstr = new FileOutputStream("test.wav");
        int nRead = 0;
        byte[] buf = new byte[1024 * 32];
        while ((nRead = this.stream.read(buf, 0, buf.length)) != -1) {
        fstr.write(buf, 0 , buf.length);
        }
        this.stream.close();
        fstr.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    }
}

public class Test {
    public static void main(String[] args) {
    try {
        Process p = new ProcessBuilder("lame", "--decode", "test.mp3", "-").start();
        ErrorThread et = new ErrorThread(p.getErrorStream());
        InputThread it = new InputThread(p.getInputStream());
        et.start();
        it.start();
        p.waitFor();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    }
}
  • 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-26T04:13:07+00:00Added an answer on May 26, 2026 at 4:13 am
        fstr.write(buf, 0 , buf.length);
    

    should be

        fstr.write(buf, 0 , nRead);
    

    If the input isn’t a multiple of 32K, you’re writing the leftovers in the buffer out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a followup question to my other question : Run bat file in
This is a followup to my last question . I now have a byte[]
this is followup to this question : Assigning 1 line of a txt file
This is a followup to my question here . I would like to understand
This is a followup to this question AnsiString is a class, too? And string
This is a followup on my previous question , I am using the 2to3
This is a followup question from a previous question, which is hopefully a little
This is a followup to my previous question. Parsing file names from a character
This is a followup to this question. Here's the code I'm trying to understand
This is a followup to the question I asked here: Class Hierarchy - Data

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.