Piped streams, data lines and threads - what's the bug?

Please, help!
What is wrong here and what should I do to make it running?
Strictly speaking, one thread becomes blocked (in) and another runs in a short circuit (out).
The code is:
    TargetDataLine stdin;
    SourceDataLine stdout;
    PipedInputStream pipein;
    PipedOutputStream pipeout;
    public void pipeDirectly() throws Exception {
        stdin = AudioSystem.getTargetDataLine(DEFAULT_FORMAT);
        stdout = AudioSystem.getSourceDataLine(DEFAULT_FORMAT);
        pipein = new PipedInputStream();
        pipeout = new PipedOutputStream(pipein);
        stdin.open(DEFAULT_FORMAT, 16384);
        stdout.open(DEFAULT_FORMAT, 16384);
        stdin.start();
        stdout.start();
        Thread in = new Thread() {
            public void run() {
                try {
                    byte[] buffer = new byte[100000];
                    while (true) {
                        int avl = stdin.available();
                        if (avl > 0) {
                            stdin.read(buffer, 0, avl);
                            pipeout.write(buffer, 0, avl);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    throw new RuntimeException(ex);
        Thread out = new Thread() {
            public void run() {
                try {
                    byte[] buffer = new byte[100000];
                    while (true) {
                        int pipeAvl = pipein.available();
                        int outAvl = stdout.available();
                        int avl = Math.min(pipeAvl, outAvl);
                        if (avl > 0) {
                            int read = pipein.read(buffer, 0, avl);
                            stdout.write(buffer, 0, read);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    throw new RuntimeException(ex);
        out.start();
        in.start();
        in.join();
    }Thank you!

Actually, tried.
There were one or two passes of "in" thread and repeating pipeAvl=0 in "out".
I have watched the thread state (IDE debugger) and realized that these things were called inside "in" thread:
wait():-1; java.lang.Object
awaitSpace():204; java.io.PipedInputStream
receive():161; java.io.PipedOutputStream
write(): 129; java.io.PipedOutputStream
run(): <my method location>
the numbers are actually the number of line from source. -1 is for native method.
Why it behaves like this? I don't understand.
To compare, this code works almost beautifully:
    TargetDataLine stdin;
    SourceDataLine stdout;
    PipedInputStream pipein;
    PipedOutputStream pipeout;
    public void pipeDirectly() throws Exception {
        stdin = AudioSystem.getTargetDataLine(DEFAULT_FORMAT);
        stdout = AudioSystem.getSourceDataLine(DEFAULT_FORMAT);
        pipein = new PipedInputStream();
        pipeout = new PipedOutputStream(pipein);
        Thread in = new Thread() {
            public void run() {
                try {
                    stdin.open(DEFAULT_FORMAT, 16384);
                    stdout.open(DEFAULT_FORMAT, 16384);
                    stdin.start();
                    stdout.start();
                    byte[] buf = new byte[100000];
                    while (true) {
                        int avl = stdin.available();
                        stdin.read(buf, 0, avl);
                        stdout.write(buf, 0, avl);
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
        in.start();
        in.join();
    }Message was edited by:
MaxBuzz

Similar Messages

  • It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is

    It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is there some simple setting out there that will just "make it so?"@

    The video I am watching this guy is just dragging every line to make curves.  And every anchor point is a corner.  He is not switching back and forth between the pen and the anchor points tool, and he is not using the convert points tool.  He draws a curved line and starts another straight line only to curve it with a click and a drag.  It is super efficient, and I could save a world of time if I could figure out what he is doing.

  • Two fields about material in AFKO: PLNBEZ and STLBEZ,what's the difference?

    Two fields about material in AFKO: PLNBEZ and STLBEZ,what's the difference?
    correct answers will be rewarded.
    thanks in advance

    Hi,
    First of all AFKO is table for Production Order Master Data. So it covers all data related BOM , Routing etc. So In order to distinguish material field related to BOM & Routing  these two different fields are there in AFKO table.
    PLNBEZ is the field for material assigned to routing operation
    STLBEZ is the field for material which is part of BOM
    Hope this clears your doubt.
    Regards,
    Tejas
    Edited by: Tejas  Pujara on Oct 8, 2008 8:22 AM

  • My apps will not download. It says that they cannot be downloaded at this time. I just brought my Iphone5 32gb today. I have my data plan turned on.What's the problem?

    My apps will not download. It says that they cannot be downloaded at this time. I just brought my Iphone5 32gb today. I have my data plan turned on.What's the problem?

    Ok, it sounds like you are getting to the final step. (i.e., Your on your iPhone, showing a good Wi-Fi connection, you are using the App Store and have selected the App you want.  The small Icon for your App is showing a bar at the bottom that has an open "fill bar" that is going to track the download and installation of the App.  But at this point you get an Error Message.  The Error Message Says, "?????"  Try again latter?  What?
    Just for fun, try downloading the App while you and your iPhone are as close to the Wi-Fi Router as possible.  Lets see if you are just experiencing a weak Wi-Fi signal.  This can cause App Downloads to fail.

  • Hi - I am looking for the Adobe Illustrator 2014 1.2 (or .0.2) bugfix update for Mac - and it is not visible in the Adobe Creative Cloud Packager (Mac version). The only update visible is Illustrator CC 2014.1  - which is what introduced the bugs.

    Hi - I am looking for the Adobe Illustrator 2014 1.2 (or .0.2) bugfix update for Mac - and it is not visible in the Adobe Creative Cloud Packager (Mac version). The only update visible is Illustrator CC 2014.1  - which is what introduced the bugs.
    The only thing that I can think of that might be causing the issues that I have a Mac Mini on Mavericks.
    Dave

    Hi
    I have discovered that my question above is a non-question. A user triggered by looking at the below article about Illustrator 2014 cc 17.0.2
    http://helpx.adobe.com/illustrator/release-note/illustrator-17-0-2-release-notes.html 
    He had recently upgraded from wht we now know is 18.0 to 18.1 which is the latest version. He read the above artic
    le and supposed that it was a bug fix release for his version - because the v17 ov18 number is not often displayed. It is usually just 2014 CC.
    I have asked him to post a bug report about Adobe Illustrator CC 2014.1
    Dave

  • If i bounce my project the bounced file is not the same as the original. it has about ten seconds at the beginning free and the end is 10 sec cut off. what is the bug?

    if i bounce my project the bounced file is not the same as the original.
    it has about ten seconds at the beginning free and the end is 10 sec cut off.
    what is the bug?
    i start the bouncing with the transport lokator as 1 1 1   1
    and ends where it sould be over.
    but the first 10 seconds are silent then it starts with the beginning of the song and the last 10 seconds are cut off.

    hello,
    this is a screeshot of my problem.
    the first pic as it should be
    second  with my problem
    this happens after some bounces and not regular.
    i dont wont to have this.
    i have two pics i would like sending to you.
    thanx,

  • HT1222 ipad apps 1 I lost all after I installed new windows and I tried to connect it between your computer and iPad, what's the solution? (Please Inbox : Bambangtjio@yahoo.o.id) Thanks

    ipad apps 1 I lost all after I installed new windows and I tried to connect it between your computer and iPad, what's the solution? (Please Inbox : [email protected]) Thanks

    Hi,
    Sounds like it isn't to serious. the Bluetooth connection had an error and that is that generated
    the Problem report.
    When the Blackberry started to use Bluetooth the "gold standard" was using Microsoft's
    "native" windows drivers. Now, every major PC company has there own version
    Thus the problem report.
    There is  rather involved and lengthy procedure to check and install the correct Bluetooth drivers
    in the Dell, but I really don't think you want to take that on.( Nod you head and say H*LL YES)
    Here is what I propose;
    The problem report needs to be resolved or it wont go away. Read the manual, call Dell,
    try apologizing to it and that you'll never never do it again, what ever it takes!
    Make the best investment you can make for your Blackberry, buy a media card.
    All the memory in the BB is dynamic, this facilitates the functions of the phone.
    By storing media in that memory, you effect are wasting X amount for file storage.
    Store all media and files on the media card, and you will have a smooth running device.
    They run about $25.00usd, they are easy to install, and they also make moving your
    media a snap. You will need the USB adapter that came with it, but you can get that at
    your local carrier store.
    So if you agree with this I need some info.
    On the Blackberry go to the options icon,click then scroll up to ABOUT.
    I need your software version number, it's listed in this format: 4.x.x.xxx.
    Send it back to me and I can tell you what size card you can get.
    Let me know your thoughts!
    Thanks,
    Bifocals
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • I want to know about wen the iphone 5 launch in india and also what will the price

    i want to know about wen the iphone 5 launch in india and also what will the price

    Anyone here knows or has access to the same info that you do or can access.
    If Apple has a website and online store in India, check Apple's website in India for an announcement.

  • I want to buy an ipad mini Wifi Cellular and use it in Central Asia,so there are two models: A1454 and A1455,what is the difference?

    I want to buy an ipad mini Wifi Cellular and use it in Central Asia,so there are two models: A1454 and A1455,what is the difference?

    Either will work fine in Central Asia as loge ad the carries support GSM (almost all do).
    One of the iPads will only work with the AT&T GSM) network if you are in the USA and the Other with the Virizon network (uses CDMA, not GSM/SIM) if you are in the USA

  • HT4847 How i can download my backup data? And how to manage the data on i Cloud?

    How i can download my backup data? And how to manage the data on i Cloud?

    You can't download an iCloud backup, except to restore it to your device should you ever need to.
    iCloud data can be managed within the apps on your iPad.  Any changes to the data within the apps corresponding to the data you are syncing with iCloud will take place in iCloud.  You can also manage some of this data on icloud.com from your computer.
    This article explains ways to manage your iCloud storage space, should you need to reduce you iCloud storage: http://support.apple.com/kb/ht4847.

  • Query weblgoic runtime JVM and thread that carry the user credential

    Hi there,
    So far as I know, weblogic keeps track of user credentials from
    different JVM and different thread. However, for the same thread within
    same JVM, weblogic only keep on user credential in the EJBContext. So,
    is there any way or any API for me to query the JVM and thread that
    carries the user credential? My purpose is to prevent second login from
    the same JVM in the same thread.
    Thanks,
    Cathy

    Hi there,
    So far as I know, weblogic keeps track of user credentials from
    different JVM and different thread. However, for the same thread within
    same JVM, weblogic only keep on user credential in the EJBContext. So,
    is there any way or any API for me to query the JVM and thread that
    carries the user credential? My purpose is to prevent second login from
    the same JVM in the same thread.
    Thanks,
    Cathy

  • Run the data copy and comments copy with the same key

    I want to Run the data copy and comments copy with the same key.
    I tried to challenge in the following way, but it is an error.
    1. Add the process in the process chain [/ CPMB / COPY] process in the process chain that could be new to copy the chain [/ CPMB / COPY_COMMENTS] (see capture)
    2. Select the newly can process chain to add a package, make a change to the script as follows:
    PROMPT(RADIOBUTTON,%TARGETMODE%,"Handling of records",0,{"Copy records with match key","Copy by replacing data in same data region of Entity, Category, Time and Audit ID"},{"0","2"})
    PROMPT(RADIOBUTTON,%RUNLOGIC%,"Select whether to run default logic for stored values after copying",0,{"Yes","No"},{"1","0"})
    PROMPT(RADIOBUTTON,%CHECKLCK%,"Select whether to check work status settings when importing data.",1,{"Yes, check for work status settings before importing","No, do not check work status settings"},{"1","0"})
    PROMPT(COPYMOVEINPUT,%SELECTION%,%TOSELECTION%,"Select the members to COPY and where to",%DIMS%,0)
    INFO(%TEMPNO1%,%INCREASENO%)
    INFO(%ACTNO%,%INCREASENO%)
    INFO(%SELECTION_KEYDATE%,)
    TASK(/CPMB/COPY_COMMENTS,SELECTION,%SELECTION%)
    TASK(/CPMB/COPY_COMMENTS,TOSELECTION,%TOSELECTION%)
    TASK(/CPMB/COPY_COMMENTS,CHECKLCK,%CHECKLCK%)
    TASK(/CPMB/CM_CONVERT,OUTPUTNO,%TEMPNO1%)
    TASK(/CPMB/CM_CONVERT,ACT_FILE_NO,%ACTNO%)
    TASK(/CPMB/CM_CONVERT,SAPPSET,%APPSET%)
    TASK(/CPMB/CM_CONVERT,SAPP,%APP%)
    TASK(/CPMB/CM_CONVERT,SELECTION,%SELECTION%)
    TASK(/CPMB/CM_CONVERT,TOSELECTION,%TOSELECTION%)
    TASK(/CPMB/CM_CONVERT,KEYDATE,%SELECTION_KEYDATE%)
    TASK(/CPMB/CLEAR_SOURCE_CUBE,CHECKLCK,1)
    TASK(/CPMB/CLEAR_SOURCE_CUBE,SELECTION,%TOSELECTION%)
    TASK(/CPMB/CLEAR_SOURCE_CUBE,KEYDATE,%SELECTION_KEYDATE%)
    TASK(/CPMB/CLEAR_SOURCE_CUBE,DUMPLOADMODE,3)
    TASK(/CPMB/APPEND_LOAD,PREPROCESSMODE,0)
    TASK(/CPMB/APPEND_LOAD,TARGETMODE,0)
    TASK(/CPMB/APPEND_LOAD,INPUTNO,%TEMPNO1%)
    TASK(/CPMB/APPEND_LOAD,ACT_FILE_NO,%ACTNO%)
    TASK(/CPMB/APPEND_LOAD,RUNLOGIC,1)
    TASK(/CPMB/APPEND_LOAD,CHECKLCK,1)
    TASK(/CPMB/APPEND_LOAD,KEYDATE,%SELECTION_KEYDATE%)

    We performed similar transfer of data from one planning model to another using DM package linked to BADI. In your scenario there is additional complexity of doing lookup from DSO and should be possible.
    Also check these references for performing lookup in DSO.
    abap code to populate data from DSO
    something about SAP: How to look for DSO&amp;#8217;s tables?

  • For iPhone and Android, what is the best file format for watching videos?

    For iPhone and Android, what is the best file format for watching videos?

    You can try these setting. They are from CS5.5 but should work in CS4.
    Make sure you check Use Max. Render Quality.

  • If i have to get a new iphone but i want to save my pictures and video, what is the beve way without uploading them all to my computer

    if i have to get a new iphone but i want to save my pictures and video, what is the beve way without uploading them all to my computer

    Set up DROPBOX account on computer and upload pictures to computer.

  • I purchased the sticker from the application LINE and they already deducted the money from my account but I didn't get anything. Who should I contact?

    I purchased the sticker from the application LINE and they already deducted the money from my appstore account but I didn't get anything. Who should I contact?

    All you can do is contact ...
    Apple - Support - iTunes Store - Contact Us

Maybe you are looking for