ZipInputStream.getNextEntry() closes stream?

I have this functionality wherein i need to read from the same zipfile, but at different times. But once I've read it the first time, it won't let me do it again, it throws a -
java.io.IOException: Stream closed.
at jazz.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:143)
I've tried assigning the ZipInputStream I have to another (like a temp zipfile) and then trying to re-read from the original zipfile, but it still throws me the error.
Code -
ZipInputStream zis = mResourceFiles; (this is the original zipfile)
if (null != zis) {
String filename = "";
while ((filename = zis.getNextEntry().getName()) !=null) {
// add entry to xml file
sLog.debug("in zis==" + filename);
... do something .....
and then there's another method that uses the same zipfile (mResourceFiles - which is a member variable) and tries to read from it.
I'm not closing the stream anywhere. I understand that I cannot re-read from a zipfile once I've read from it. What then could be the soln to this?
Thanks in advance!
HS

Hmm .. I've tried creating a new ZipInputStream too - here's what I'm really doing ..
I have a method that reads all files in the ZipInputStream (member variable in class) by doing this -
ZipInputStream zis = new ZipInputStream(mResources);
if (null != zis) {
     ZipEntry entry;
     int offset = 0;
     while ((entry = zis.getNextEntry()) !=null) {
     // add entry to zip file
     zos.putNextEntry(entry); // ZipOutputStream
     // write file
     byte[] buf = new byte[1024];
     int len;
     while ((len = zis.read(buf)) > 0){
     zos.write(buf, 0, len);
     zos.closeEntry();
Now in another method, I need to get all entries from the same zipfile - reassigning to a new ZipInputStream still throws me the 'Stream closed' error.
Also, creating a new instance of ZipInputStream (like above) instead of just assigning it to another ZipInputStream throws me the following error -
Caused by: jazz.util.zip.ZipException: EOF in header
at jazz.util.zip.ZipInputStream.readLeByte(ZipInputStream.java:115)
at jazz.util.zip.ZipInputStream.readLeShort(ZipInputStream.java:125)
at jazz.util.zip.ZipInputStream.readLeInt(ZipInputStream.java:133)
at jazz.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:147)
I use ZipInputStream, as opposed to ZipFile as I get passed the zipfile as a ZipInputStream from another class.
Need help!! :)

Similar Messages

  • HowTo Close stream on exception (FindBug)

    Hi there.
    I've just started to use the tool FindBugs which seems to work all right as far as it goes.
    But it claims, that in the following code the method may "fail to close stream on exception":
         void writeToFile(String fileName){
              System.out.print("Creating "+fileName+" ..");
              try {
                   FileOutputStream fos = new FileOutputStream(new File(fileName));
                   PrintWriter o = new PrintWriter(fos);  //this line is marked as error-prone
                   o.println("Some String");
                   o.close();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              System.out.println(".done");
         }Whereas if I comment out the line with the o.println-call, everything's fine again for "FindBugs".
    I have absolutely no clue to what's meant by "on exception", since neither the line itself nor the following line throws an Exception.
    (BTW: adding an "finally" block or closing the stream after the try-catch-block doesn't seem to solve the problem for FindBugs).
    So, what's my problem? The code seems to work yet. But FindBugs seems to be a neat tool and since I don't like having code that might fail to close streams on exceptions,
    I'd like to hear from some of you how you'd code a simple block like that.
    (Add to that: I hate being corrected by a programme (At least as long as this fucker seems to be smarter than me ;) So now it's time for me to learn!! )
    Any suggestions about how to improve my programming technique are gratefully taken, as well as blind guessing around about what the hell FindBugs thinks I should do better.
    -T-

    Hi,
    This is the first time I am using findbugs tool. I have this piece of code
    <target if="javadoc.packages" name="findbug" >
    <!--<available file="etc/javadoc_build.inc" property="javadoc.buildinc"/>-->
    <findbugs home="D:\bin\common\_lib\build\findbugs"
    output="xml"
    outputFile="bcel-fb.xml" >
              <!--<auxClasspath path="${basedir}/lib/Regex.jar" />-->
              <sourcePath path="C:\java.zip" />
    <class location="C:\java.zip" />
    </findbugs>
    </target>
    My questions are
    1)Is the <auxClasspath> extension required.
    2)on running ant task, i get the following error
    D:\deepak\buildProcess_2\logging>ant findbug
    Buildfile: build.xml
    [taskdef] Could not load definitions from resource tasks.properties. It could not be found.
    findbug:
    findbug:
    BUILD FAILED
    file:D:/deepak/buildProcess_2/_setup/docs.xml:190: Could not create task or type of type: findbugs.
    Ant could not find the task or a class this task relies upon.
    This is common and has a number of causes; the usual
    solutions are to read the manual pages then download and
    install needed JAR files, or fix the build file:
    - You have misspelt 'findbugs'.
    Fix: check your spelling.
    - The task needs an external JAR file to execute
    and this is not found at the right place in the classpath.
    Fix: check the documentation for dependencies.
    Fix: declare the task.
    - The task is an Ant optional task and optional.jar is absent
    Fix: look for optional.jar in ANT_HOME/lib, download if needed
    - The task was not built into optional.jar as dependent
    libraries were not found at build time.
    Fix: look in the JAR to verify, then rebuild with the needed
    libraries, or download a release version from apache.org
    - The build file was written for a later version of Ant
    Fix: upgrade to at least the latest release version of Ant
    - The task is not an Ant core or optional task
    and needs to be declared using <taskdef>.
    Remember that for JAR files to be visible to Ant tasks implemented
    in ANT_HOME/lib, the files must be in the same directory or on the
    classpath
    Please neither file bug reports on this problem, nor email the
    Ant mailing lists, until all of these causes have been explored,
    as this is not an Ant bug.
    Total time: 3 seconds
    Anyone suggest me a solution.
    bye,
    with regards,
    Deepak.

  • Close stream

    Hi,
    I have this simple case to read an output stream of an external process:
    Process proc = Runtime.getRuntime().exec(parameters);
                   InputStream is = proc.getInputStream();
                   InputStreamReader isr = new InputStreamReader(is);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ((line = br.readLine()) != null) {
                        // do something
                   br.close();
                   isr.close();
                   is.close();
    is it necessary close is, isr and br? Or is it enough close br only?
    Thanks,
    Giulio

    It is sufficient to close br, because br's close method calls its nested reader, and so on.

  • Incomplete pictures

    My applet (http://www.partnumber.com/testapplet.html) has lots of icons.
    To speed-up loading, they're archived in a ZIP file. The applet has acces to this ZIP file as well as individual gif files of the images.
    Some icons do not load properly, but I have a workaround: if the image reports an error (either from a MediaWatcher, or the paint() method, or the imageUpdate() method), I just reload it from a loose gif file.
    The problem that remains is that some images are fine as far as Java is concerned, yet they are often only partially drawn (the bottom is missing).
    After working on this for a week, I am ready to ask for help, please.
    Thanks,
    Davide
    Some details:
    There's no problem when running from the Hard Drive.
    There's no problem when running over the internet, using just the loose gif files.
    When running over the internet, using the ZIP file, particular images are prone to being mangled.
    A given computer and browser combination will mangle the same icon more or less consistently. A different browser, or a different computer, will mangle other icons.
    If I recreate the ZIP file identically, the behavior is the same. If I recreate it by placing the icons in a different order, then the icons that are mangled change.
    Using a MediaWatcher to wait until each icon is fully loaded before I load the next doesn't make a difference.
    If I look at the imageUpdate() calls, I see that, while in a good image the x value increases from 0 to 31 (the icons are 32 pixels high), in a mangled image is stops earlier, and then it gives me the ALLBITS flag, as if all were fine. (I thought I could monitor that x value, and determine if a icon is incomplete, but certain VMs do not report that x value.)
    The getHeight() method returns the proper height: 32.
    If I add a background color, I can see that the image is the right size: a full 32 pixels high, even though only a few lines of it are actually rendered.
    The ZIP archive uses no compression.
    The way I read icons is:
    imageData = new byte[MaxIconFileSize];
    zipInputStream.read(imageData, 0, MaxIconFileSize);
    theIcon = toolKit.createImage(imageData);Roughly, the code is:
    public class PartNumber extends Applet{
         private     PostReadThread     postReadThread;     // The thread that lets me start reading the rest
         /* init method */
         public void init() {
              // Schedule finish reading the files after I am done initializing
              postReadThread = new PostReadThread();     // Create a new thread for reading the rest
              postReadThread.start();                         // Start it
    }     // End of PartNumber
    class PostReadThread extends Thread {
         public void run() {     // Receives a flag set if we want to scan inside a class as well
              PictButton.loadImages();          // Read the icons
    }     // End of class PostReadThread
    class PictButton extends Canvas implements ImageObserver {
         private     static Hashtable     iconTable = new Hashtable();// Dictionary of the icon for each Pict
         private String     myIconFileName;     // The name of the file that has my icon
         /* PictButton method */
         // Constructor
         PictButton(String myIconFileName) {      // Receives the file name of my icon
              this.myIconFileName = myIconFileName;     // Save the input parameters
              // Get my icon, either from the dictionary with the icons, or directly from a folder
              getIcon(myIconFileName, false);     // At this point we won't do anything with it:
                   // this is just to make sure it's loaded. Flag that it can be from a ZIP file
         /* loadImages method */
         // Read the icons from a ZIP file
         static void loadImages() {
              // Load the icons file
              try {
                   // Declare some local variables
                   String iconFileName; int nameLength; Image theIcon; byte[] imageData;
                   // Get a handle to the tool kit from a dummy button
                   Toolkit toolKit = new Button().getToolkit();
                   // Open the ZIP archive
                   // Get the URL of the ZIP file with the icons
                   URL theURL = new URL(PartNumber.ID.getDocumentBase(), PartNumber.IconPath);
                   // Open a stream for the ZIP file
                   InputStream inputStream = theURL.openStream();
                   // Open a stream for the ZIP archive
                   ZipInputStream zipInputStream = new ZipInputStream(inputStream);
                   // Extract each file in the archive, and create an Image from it
                   // Get the first file in the ZIP archive
                   ZipEntry zipEntry = zipInputStream.getNextEntry();
                   while(zipEntry != null) { // For each entry in the archive...
                        iconFileName = zipEntry.getName(); // Get its name
                        nameLength = iconFileName.length(); // Get the length of its name
                        if(iconFileName.substring(nameLength -4).toLowerCase().equals(".gif")) {
                             // If it's a gif file...
                             // Extract the basic file name
                             iconFileName = iconFileName.substring(0,nameLength -4);
                             // Get this image
                             // Clear a byte array in which we'll put the data
                             imageData = new byte[MaxIconFileSize];
                             // Read the image data from the gif file
                             zipInputStream.read(imageData, 0, MaxIconFileSize);
                             // Ask the tool kit to create an image for it
                             theIcon = toolKit.createImage(imageData);
                        // Get the next file in the archive
                        zipInputStream.closeEntry();
                        zipEntry = zipInputStream.getNextEntry();
                   // Close the archive
                   inputStream.close();
                   zipInputStream.close();
              } catch (Exception e) {     // If unable to do so...
                   // Report the problem
                   System.err.println("Unable to open Zipped icon file");
                   e.printStackTrace();
         /* getIcon method */
         // Get the icon with a given file name
         // Get it either from the dictionary with the icons, or directly from a folder
         static Image getIcon(String iconFileName, boolean fromLoose){
              // Receives the icon's file name,
              // and a flag set if I insist that it must be taken from a loose file (not from a ZIP file)
              Image theIcon = null;
              // Try to get the icon from the dictionary
              if(!fromLoose) theIcon = (Image)iconTable.get(iconFileName);// Use the file name as a key
              // If not there, get it directly from a loose file
              if(theIcon == null) { // If not yet loaded from the ZIP file...
              // Get the path to the image for this part class
                   String iconPath = new String(PartNumber.IconDir + iconFileName + ".gif");
                   try {
                        // Open the file and create an image
                         = PartNumber.ID.getImage(PartNumber.ID.getDocumentBase(), iconPath);
                         // Store the icon in the dictionary, using the file name as a key
                        iconTable.put(iconFileName,theIcon);
                   } catch (Exception e) {     e.printStackTrace();}
              // Return a handle to the icon
              return theIcon;
         /* paint method */
         // Paint myself
         public void paint(Graphics theGraphic) { // Receives the Graphics
              // Draw my icon
              // Get my icon, either from the dictionary with the icons, or directly from a folder
              // Flag that it can be from a ZIP file
              Image myIcon = getIcon(myIconFileName, false); .
              if(myIcon != null) {     // If I have an icon yet...
                   theGraphic.setColor(Color.black);     // Draw in black
                   try{theGraphic.drawImage(myIcon,0,0,this);}// Draw my icon. I'm its ImageObserver
                   catch (Exception e) {
                        // Get the icon again, but this time it must be from the loose file,
                        //  because the there was an error getting it from the ZIP file
                        getIcon(myIconFileName, true);
         /* imageUpdate method */
         // Called by Java when something is happening with my icon
         public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
              if ((infoflags & ALLBITS) != 0) repaint();
              // Return a flag set if we want to get more updates
              return (infoflags & (ALLBITS | ERROR)) == 0;
    } // End of PictButton

    Here's more info.
    This is what imageUpdate() receives.
    When the image is completed:
    infoflags:3 x:0 y:0 width:104 height:32
    infoflags:4 x:0 y:0 width:0 height:0
    infoflags:8 x:0 y:0 width:104 height:1
    infoflags:8 x:0 y:1 width:104 height:1
    infoflags:8 x:0 y:2 width:104 height:1
    infoflags:8 x:0 y:3 width:104 height:1
    infoflags:8 x:0 y:4 width:104 height:1
    infoflags:8 x:0 y:5 width:104 height:1
    infoflags:8 x:0 y:6 width:104 height:1
    infoflags:8 x:0 y:7 width:104 height:1
    infoflags:8 x:0 y:8 width:104 height:1
    infoflags:8 x:0 y:9 width:104 height:1
    infoflags:8 x:0 y:10 width:104 height:1
    infoflags:8 x:0 y:11 width:104 height:1
    infoflags:8 x:0 y:12 width:104 height:1
    infoflags:8 x:0 y:13 width:104 height:1
    infoflags:8 x:0 y:14 width:104 height:1
    infoflags:8 x:0 y:15 width:104 height:1
    infoflags:8 x:0 y:16 width:104 height:1
    infoflags:8 x:0 y:17 width:104 height:1
    infoflags:8 x:0 y:18 width:104 height:1
    infoflags:8 x:0 y:19 width:104 height:1
    infoflags:8 x:0 y:20 width:104 height:1
    infoflags:8 x:0 y:21 width:104 height:1
    infoflags:8 x:0 y:22 width:104 height:1
    infoflags:8 x:0 y:23 width:104 height:1
    infoflags:8 x:0 y:24 width:104 height:1
    infoflags:8 x:0 y:25 width:104 height:1
    infoflags:8 x:0 y:26 width:104 height:1
    infoflags:8 x:0 y:27 width:104 height:1
    infoflags:8 x:0 y:28 width:104 height:1
    infoflags:8 x:0 y:29 width:104 height:1
    infoflags:8 x:0 y:30 width:104 height:1
    infoflags:8 x:0 y:31 width:104 height:1
    infoflags:32 x:0 y:0 width:104 height:32When the image isn't completed:
    infoflags:3 x:0 y:0 width:104 height:32
    infoflags:4 x:0 y:0 width:0 height:0
    infoflags:8 x:0 y:0 width:104 height:1
    infoflags:8 x:0 y:1 width:104 height:1
    infoflags:8 x:0 y:2 width:104 height:1
    infoflags:8 x:0 y:3 width:104 height:1
    infoflags:32 x:0 y:0 width:104 height:32

  • How do I close nested streams?

    Hi,
    I learned that it is very important to close streams. But how do I close a nested stream?
    //Open new zip input stream with a nested file input stream
    zip_input_stream = new ZipInputStream(new FileInputStream(zip_archive));
    //Close zip input stream
    zip_input_stream.close();
    //How do I close the file input stream??

    BalusC wrote:
    da.futt wrote:
    There's something to be said for this. After all, there's no guarantee at all that a wrapping stream will close its delegate, is there?
    Under each [http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/index.html] tells:
    Similarly, when closing chained streams, you only need to close the outermost stream class because the close() call is automatically trickled through all the chained classes
    When using legacy classes... sure. But I hope you'll readily admit it would be very easy to write an InputStream that doesn't "trickle through"
    Hey, don't look at me like this! I wouldn't bother either. I'm just trying to comfort filestream's paranoia! :)

  • Problem with the streams....

    Dear All,
    I am trying to zip a file in the client side and sending it to the server side machine......there, i am trying to unzip it and writting it over there...for this, i am using a seperate program in the client side and in the server side.................................
    In the client program, after opening all the necessary streams and all formalities, i am using the code...
    "InputStream in = urlconnection.getInputStream();
    while (in.read()!=-1);"
    only if i use the above code, the zipped file is transfered to my server machine...but in this case, the link with the server is not getting disconnected...i mean the command prompt remains alive, without stopping...what i inferred is, my control is got into the above said "InputStream in = urlconnection.getInputStream();"...indefinitely...
    so i tried of removing the above said statement.....in this case, the zipped file is NOT getting written in my server machine....
    what to do???
    any suggestions please...waiting for the reply very anxiously, refreshing this site for every 2 minutes....
    sakthivel s.
    snippet code for ur reference...
    Client side
    try
    ZipOutputStream zipoutputstream = new ZipOutputStream(urlconnection.getOutputStream());
    ZipEntry zipentry = new ZipEntry(filename);
    zipentry.setMethod(ZipEntry.DEFLATED);
    zipoutputstream.putNextEntry(zipentry);
    byte bytearray[] = new byte[1024];
    File file = new File(filenamedir);
    FileInputStream fileinputstream = new FileInputStream(file);
    BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream);
    int length = 0;
    while((length=bufferedinputstream.read(bytearray)) != -1)
    zipoutputstream.write(bytearray,0,length);
    fileinputstream.close();
    bufferedinputstream.close();
    zipoutputstream.flush();
    zipoutputstream.finish();
    zipoutputstream.closeEntry();
    zipoutputstream.close();
    InputStream in = urlconnection.getInputStream();
    while (in.read()!=-1); // the said while loop....................
    System.runFinalization();
    urlconnection.getInputStream().close();
    urlconnection.disconnect();
    the way of connecting witht the server : (just a snippet of the code)
    URL serverURL = new URL("http://192.168.10.55:8001/servlet/uploadservlet");
    HttpURLConnection.setFollowRedirects(true);
    urlconnection= (HttpURLConnection)serverURL.openConnection();
    urlconnection.setDoOutput(true);
    urlconnection.setRequestMethod("POST");
    urlconnection.setDoOutput(true);
    urlconnection.setDoInput(true);
    urlconnection.setUseCaches(false);
    urlconnection.setAllowUserInteraction(true);
    urlconnection.setRequestProperty("Cookie",cookie);
    urlconnection.connect();
    Server Side:
    javax.servlet.ServletInputStream servletinputstream = httpservletrequest.getInputStream();
    ZipInputStream zipinputstream = new ZipInputStream(servletinputstream);
    ZipEntry zipentry = null;
    String directory="c:\\test"; // the unzipped file should be written to this directory...
    try
    File file = new File(directory);
    if(!file.exists())
    file.mkdirs();
    catch(Exception exp)
    {System.out.println("I am from Server: " + exp);}
    try
    zipentry = zipinputstream.getNextEntry();
    if(zipentry != null)
    int slash = zipentry.getName().lastIndexOf(File.separator) + 1;
    String filename = zipentry.getName().substring(slash);
    File file1 = new File(directory + File.separator + filename);
    FileOutputStream fostream = new FileOutputStream(file1);
    BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fostream);
    byte abyte0[] = new byte[1024];
    for(int index = 0; (index = zipinputstream.read(abyte0)) > 0;)
    bufferedoutputstream.write(abyte0, 0, index);
    servletinputstream.close();
    bufferedoutputstream.flush();
    bufferedoutputstream.close();
    zipinputstream.closeEntry();
    zipinputstream.close();
    fostream.flush();
    fostream.close();
    catch(IOException ioexception)
    {System.out.println("IOException occured in the Server: " + ioexception);ioexception.printStackTrace();}
    P.S: I am not getting any error in the server side or cleint side...the only problem is, the command prompt(where i am running my cleint program) is getting standing indefinitely...i have to use control-c to come to the command prompt again...this is because of the while looop said in the client machine....if i remove it...the file is not gettting transfered...what to do????

    Some thoughts:
    1) please quote your code so it's readable (see http://forum.java.sun.com/faq.jsp#messageformat ).
    2) why are you calling "System.runFinalization();"?
    3) Offhand I don't see where the read would ever stop. It's waiting for an end of input from the server, but the server doesn't even begin to write output to it. What happens when you connect to your server with a browser or some other client?
    4) is it really wise to read and write one byte at a time?

  • Zip.ZipInputStream cannot extract files with Chinese chars in name

    Dear friends,
    Peace b upon u!
    I am trying to read a zip file (~3000 files)containing one
    or more files with Chinese, Japanese or Korean names, the
    getNextEntry method throws an IllegalArgumentException as below after extracting just ~300 files as below:-
    java.lang.IllegalArgumentException
            at java.util.zip.ZipInputStream.getUTF8String(Unknown Source)
            at java.util.zip.ZipInputStream.readLOC(Unknown Source)
            at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
            at testZipFiles.getZipFiles(testZipFiles.java:65)
            at testZipFiles.main(testZipFiles.java:18) issue:java.util.zip.ZipInputStream cannot extract files with Chinese chars in name
    Category java:classes_util_jarzip
    Plz let me know 1 of the ways which I can solve this issue.
    1)if someone has JAVA DCOMPILER plz send the SOURCE Code
    for the ZipInputStream.class to me..I need to edit it using 1 of the solutions as provided below which I googled.
    2)If there is an alternate or upgraded java.util.zip.ZipInputStream or any org.apache.tools.zip.* package which can read such files..If yes where I can download the same on net.
    3)Any other easier solution, which can let me extract all files (by excluding Chinese files thru CATCH) without the extractor process to fail altogether.
    On net I found that the only solution with this is:-
    - edit the new ZipEntry, remove the static initializer that calls
    the native methods initIDs().
    this step seems a bit scary, but it's according to the
    workaround
    to bug #4244499 (the workaround of Olive64, THU JUN 05
    01:55 P.M. 2003),
    that handles a similar bug at the ZipOutputStream.
    Now you have a ZipInputStream that supports multi-bytes
    entry names.
    to extract the zip file, using the fixed code that is offered
    above,
    create a function that gets an "encoding" string, a "destPath"
    string
    and a "sourceFile" (zipped) and does :
    ZipInputStream zipinputstream = null;
    ZipEntry zipentry;
    zipinputstream = new ZipInputStream(new FileInputStream
    (sourceFile),encoding);
    zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) { //for each entry to be extracted
        String entryName = zipentry.getName();
        int n;
        FileOutputStream fileoutputstream = new FileOutputStream
    ( destPath + entryName );
        while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
            fileoutputstream.write(buf, 0, n);
        fileoutputstream.close();
        zipinputstream.closeEntry();
        zipentry = zipinputstream.getNextEntry();
    }//while
    zipinputstream.close();

    Hi friend,
    We'd better to ask one question in each thread. If you have another issue, you can consider to open up a new thread in this forum.
    Now for the first question, do you mean this picture? It throws access exception in archive2.
    If so , because your extractPath is a path, not a directory.You should add +"xxx.zip". For more information, please refer to
    ZipFile.Open
    Method (String, ZipArchiveMode).
    For the second question, you can use the following code to skip the error message.
    while (true)
    try
    //do something;
    catch (Exception ex)
    { continue; }
    Good day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Zipinput/output stream

    Dear All,
         I have a problem over here, in the transfer of file from my client machine to the server machine....I am zipping the file in the client machine and sending to the server machine....In the server machine I am trying to unzip it and write it over there....
    For contacting my server, initially i am getting the authentication.....it is all correct....no problem with the authentication work...the problem over here is.............i am having 3 files to be transfered to my server machine...the first file is getting transfered....after that the command prompt is just standing idle....it is not even coming to the prompt state...it is not even thowing any errors in the server console or in the client machine....
    Below is my complete code....
    Client program: (simple java program)
    import java.io.BufferedInputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.net.*;
    import java.sql.*;
    class testprogram
    HttpURLConnection urlconnection = null;
    public static void main(String args[])
    String file1="F:/Domino/Data/Applications/Groupware/HP/input/Invcor02/param/new1.txt";
    String file2="F:/Domino/Data/Applications/Groupware/HP/input/Invcor02/param/new2.txt";
    String file3="F:/Domino/Data/Applications/Groupware/HP/input/Invcor02/param/new3.txt";
    String name1="new1.txt";
    String name2 ="new2.txt";
    String name3="new3.txt";
    testprogram tt=new testprogram();
    try
    tt.makeConnection();
    tt.zipper(file1,name1);
    tt.zipper(file2,name2);
    tt.zipper(file3,name3);
    tt.disconnectConnection();
    catch(Exception e){}
    public void zipper(String file,String name) throws Exception
    try
    ZipOutputStream zipoutputstream = new ZipOutputStream(urlconnection.getOutputStream());
    ZipEntry zipentry = new ZipEntry(name);
    zipentry.setMethod(ZipEntry.DEFLATED);
    zipoutputstream.putNextEntry(zipentry);
    byte bytearray[] = new byte[1024];
    File filedir = new File(file);
    FileInputStream fileinputstream = new FileInputStream(filedir);
    BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream);
    int length = 0;
    while((length=bufferedinputstream.read(bytearray)) != -1)
    zipoutputstream.write(bytearray,0,length);
    fileinputstream.close();
    bufferedinputstream.close();
    zipoutputstream.flush();
    zipoutputstream.finish();
    zipoutputstream.closeEntry();
    zipoutputstream.close();
    System.out.println("I am here...");
    InputStream in = urlconnection.getInputStream();
    while (in.read()!=-1);
    catch(Exception exp)
    {System.out.println("I am from client:      " + exp);}
    /* to make the URL connection with the server - begin */
    public void makeConnection()
    /* Authentication work is done over here - begin */
    String setcookie="";
    String cookie="";
    try
    URL theurl = new URL("http://192.168.10.55:8001/names.nsf?login&username=sakthivel&password=12345");
    HttpURLConnection.setFollowRedirects(false);
    HttpURLConnection hurl = (HttpURLConnection)theurl.openConnection();
    hurl.connect();
    setcookie = hurl.getHeaderField ("set-cookie");
    int index=setcookie.indexOf(";");
    cookie=(setcookie.substring(0,index)).trim();
    hurl.disconnect();
    hurl=null;
    theurl=null;
    catch(Exception exp){exp.printStackTrace();}
    /* Authentication work is done over here - end */
    /* to make the URL connection with the server - begin */
    try
    URL serverURL = new URL("http://192.168.10.55:8001/servlet/FileUploadServlet");
    urlconnection= (HttpURLConnection)serverURL.openConnection();
    urlconnection.setDoOutput(true);
    urlconnection.setRequestMethod("POST");
    urlconnection.setRequestProperty("Cookie",cookie);
    catch(Exception exp)
    {System.out.println("Client machine:   Error in Making Connection" + exp );}
    /* to make the URL connection with the server - end */
    /* to disconnect the URL connection with the server - begin */
    public void disconnectConnection()
    try
    System.runFinalization();
    urlconnection.disconnect();
    urlconnection.getInputStream().close();
    catch(Exception exp)
    {System.out.println("Client machine:   Error gets fired while disconnecting the connection" + exp);}
    /* to disconnect the URL connection with the server - end */
    My Server side Program(servlet program)
    import java.io.BufferedOutputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class FileUploadServlet extends HttpServlet
    public void init() throws ServletException
    public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws ServletException, IOException
         try{UnzipAndWriteToDir(httpservletrequest, httpservletresponse);}
         catch(Exception exp){System.out.println("I am from server............" + exp);}
    public void UnzipAndWriteToDir(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws Exception
    javax.servlet.ServletInputStream servletinputstream = httpservletrequest.getInputStream();
    ZipInputStream zipinputstream = new ZipInputStream(servletinputstream);
    ZipEntry zipentry = null;
    String directory="c:\\test";
    try
    File file = new File(directory);
    if(!file.exists())
    file.mkdirs();
    catch(Exception exp)
    {System.out.println("I am from Server: " + exp);}
    try
    zipentry = zipinputstream.getNextEntry();
    if(zipentry != null)
    int slash = zipentry.getName().lastIndexOf(File.separator) + 1;
    String filename = zipentry.getName().substring(slash);
    File file1 = new File(directory + File.separator + filename);
    BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(new FileOutputStream(file1));
    byte abyte0[] = new byte[1024];
    for(int index = 0; (index = zipinputstream.read(abyte0)) > 0;)
    bufferedoutputstream.write(abyte0, 0, index);
    bufferedoutputstream.flush();
    bufferedoutputstream.close();
    zipinputstream.closeEntry();
    zipinputstream.close();
    catch(IOException ioexception)
    {System.out.println("IOException occured in the Server:   " + ioexception);}
    }     // end of the method...
    } // end of the class
    P.S: Here, I am using the Domino Server, which is same as the Web Logic Server......Pl. post a reply....hanging over here for the past one week...any suggestion is highly appreciated....

    I have done what you describe with a "Transfer Object". I've used a wrapper around the files to be transfered with the actual files held in an array and seperate fields for status and quantity. It greatly simplified my logic to tranfer multiple files especially where there were divers requests for prossessing to be done on the files.

  • ZipInputStream & ZipEntry taking time to unzip big file

    Hi,
    We have big zip file around 2GB which needs to downloaded and unzipped. We are using ZipInputStream & ZipEntry for unzipping the files.
    This is taking around 45 min to unzip the file. Do we have better alternative for doing the same?
    Thanks in advance
    Regards,
    Ravi

    Below is the code we are using:
    public void getZipFiles(String sSourcePath, String sDestPath)
            try
                sDestPath = sDestPath + Util.getFileSeparator();
                byte[] buf = new byte[1024];
                ZipInputStream zipinputstream = null;
                ZipEntry zipentry;
                BufferedOutputStream  outBuffer =null;
                BufferedInputStream inBuffer = null;
                zipinputstream = new ZipInputStream(
                    new FileInputStream(sSourcePath));
                String sFile =sSourcePath.substring(0,  sSourcePath.indexOf("."));
            File f = new File(sFile);
            if(f.mkdir())
                System.out.println( f + " Directory Created");
            else
            System.out.println(f + " Directory is not created");
                zipentry = zipinputstream.getNextEntry();
                while (zipentry != null)
                    //for each entry to be extracted
                    String entryName = zipentry.getName();
                    int n;
                    if(zipentry.isDirectory())
                        File f1 = new File(sDestPath+zipentry.getName());
                         if(f1.mkdir())
                                System.out.println(f + " Directory Created");
                            else
                            System.out.println(f + " Directory is not created");
                    else
                    FileOutputStream fileoutputstream;
                    File newFile = new File(entryName);
                    String directory = newFile.getParent();
                    if(directory == null)
                        if(newFile.isDirectory())
                            break;
                    fileoutputstream = new FileOutputStream(sDestPath+entryName);
                    outBuffer = new BufferedOutputStream(fileoutputstream);
                    inBuffer = new BufferedInputStream(zipinputstream);
                   /* while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
                        fileoutputstream.write(buf, 0, n);*/
                    while(true){
                       int bytedata = inBuffer.read();
                      if(bytedata == -1)       break;
                      outBuffer.write(bytedata);
                    outBuffer.flush();
                    fileoutputstream.close();
                    fileoutputstream.flush();
                   // zipinputstream.closeEntry();
                    zipentry = zipinputstream.getNextEntry();
                }//while
                zipinputstream.close();
                outBuffer.close();
                inBuffer.close();
            catch (Exception e)
                e.printStackTrace();
        }Edited by: EJP on 5/02/2013 22:07: code tags

  • CTD bug in simple video streaming applet.

    I'm trying to write a simple applet to use JMF to allow an end-user to view a video stream that's being served up by VLC. It doesn't have to look immensely pretty (in fact, streamlined is what I want most). I swiped some code from the jicyshout project (http://jicyshout.sourceforge.net) which handles streaming MP3s, and borrowed a framework for an applet from one of Sun's example applets for the JMF.
    Here's my code so far:
    ** begin file SimpleVideoDataSource.java **
    import java.lang.String;
    import java.net.*;
    import java.io.*;
    import java.util.Properties;
    import javax.media.*;
    import javax.media.protocol.*;
    /* The SeekableStream and DataSource tweaks are based on the code from
    * jicyshout (jicyshout.sourcefourge.net), which was written by Chris Adamson.
    * The code was simplified (no need for mp3 metadata here), cleaned up, then
    * extended for our puposes.
    * This is a DataSource using a SeekableStream suitable for
    * streaming video using the default parser supplied by JMF.
    public class SimpleVideoDataSource extends PullDataSource {
    protected MediaLocator myML;
    protected SeekableInputStream[] seekStreams;
    protected URLConnection urlConnection;
    // Constructor (trivial).
    public SimpleVideoDataSource (MediaLocator ml) throws MalformedURLException {
    super ();
    myML = ml;
    URL url = ml.getURL();
    public void connect () throws IOException {
    try {
    URL url = myML.getURL();
    urlConnection = url.openConnection();
    // Make the stream seekable, so that the JMF parser can try to parse it (instead
    // of throwing up).
    InputStream videoStream = urlConnection.getInputStream();
    seekStreams = new SeekableInputStream[1];
    seekStreams[0] = new SeekableInputStream(videoStream);
    } catch (MalformedURLException murle) {
    throw new IOException ("Malformed URL: " + murle.getMessage());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
    fatalError("Array Index OOB: " + aioobe);
    // Closes up InputStream.
    public void disconnect () {
    try {
    seekStreams[0].close();
    } catch (IOException ioe) {
    System.out.println ("Can't close stream. Ew?");
    ioe.printStackTrace();
    // Returns just what it says.
    public String getContentType () {
    return "video.mpeg";
    // Does nothing, since this is a stream pulled from PullSourceStream.
    public void start () {
    // Ditto.
    public void stop () {
    // Returns a one-member array with the SeekableInputStream.
    public PullSourceStream[] getStreams () {
    try {
    // **** This seems to be the problem. ****
    if (seekStreams != null) {
    return seekStreams;
    } else {
    fatalError("sourceStreams was null! Bad kitty!");
    return seekStreams;
    } catch (Exception e) {
    fatalError("Error in getStreams(): " + e);
    return seekStreams;
    // Duration abstract stuff. Since this is a theoretically endless stream...
    public Time getDuration () {
    return DataSource.DURATION_UNBOUNDED;
    // Controls abstract stuff. No controls supported here!
    public Object getControl (String controlName) {
    return null;
    public Object[] getControls () {
    return null;
    void fatalError (String deathKnell) {
    System.err.println(":[ Fatal Error ]: - " + deathKnell);
    throw new Error(deathKnell);
    ** end file SimpleVideoDataSource.java **
    ** begin file SeekableInputStream.java **
    import java.lang.String;
    import java.net.*;
    import java.io.*;
    import java.util.Properties;
    import javax.media.*;
    import javax.media.protocol.*;
    /* The SeekableStream and DataSource tweaks are based on the code from
    * jicyshout (jicyshout.sourcefourge.net), which was written by Chris Adamson.
    * The code was simplified (no need for mp3 metadata here), cleaned up, then
    * extended for our puposes.
    /* This is an implementation of a SeekableStream which extends a
    * BufferedInputStream to basically fake JMF into thinking that
    * the stream is seekable, when in fact it's not. Basically, this
    * will keep JMF from puking over something it expects but can't
    * actually get.
    public class SeekableInputStream extends BufferedInputStream implements PullSourceStream, Seekable {
    protected int tellPoint;
    public final static int MAX_MARK = 131072; // Give JMF 128k of data to "play" with.
    protected ContentDescriptor unknownCD;
    // Constructor. Effectively trivial.
    public SeekableInputStream (InputStream in) {
    super (in, MAX_MARK);
    tellPoint = 0;
    mark (MAX_MARK);
    unknownCD = new ContentDescriptor ("unknown");
    // Specified size constructor.
    public SeekableInputStream (InputStream in, int size) {
    super (in, Math.max(size, MAX_MARK));
    tellPoint = 0;
    mark(Math.max(size, MAX_MARK));
    unknownCD = new ContentDescriptor ("unknown");
    // Reads a byte and increments tellPoint.
    public int read () throws IOException {
    int readByte = super.read();
    tellPoint++;
    return readByte;
    // Reads bytes (specified by PullSourceStream).
    public int read (byte[] buf, int off, int len) throws IOException {
    int bytesRead = super.read (buf, off, len);
    tellPoint += bytesRead;
    return bytesRead;
    public int read (byte[] buf) throws IOException {
    int bytesRead = super.read (buf);
    tellPoint += bytesRead;
    return bytesRead;
    // Returns true if in.available() <= 0 (that is, if there are no bytes to
    // read without blocking or end-of-stream).
    public boolean willReadBlock () {
    try {
    return (in.available() <= 0);
    } catch (IOException ioe) {
    // Stick a fork in it...
    return true;
    // Resets the tellPoint to 0 (meaningless after you've read one buffer length).
    public void reset () throws IOException {
    super.reset();
    tellPoint = 0;
    // Skips bytes as expected.
    public long skip (long n) throws IOException {
    long skipped = super.skip(n);
    tellPoint += skipped;
    return skipped;
    // Trivial.
    public void mark (int readLimit) {
    super.mark (readLimit);
    // Returns the "unknown" ContentDescriptor.
    public ContentDescriptor getContentDescriptor () {
    return unknownCD;
    // Lengths? We don't need no stinkin' lengths!
    public long getContentLength () {
    return SourceStream.LENGTH_UNKNOWN;
    // Theoretically, this is always false.
    public boolean endOfStream () {
    return false;
    // We don't provide any controls, either.
    public Object getControl (String controlName) {
    return null;
    public Object[] getControls () {
    return null;
    // Not really... but...
    public boolean isRandomAccess () {
    return true;
    // This only works for the first bits of the stream, while JMF is attempting
    // to figure out what the stream is. If it tries to seek after that, bad
    // things are going to happen (invalid-mark exception).
    public long seek (long where) {
    try {
    reset();
    mark(MAX_MARK);
    skip(where);
    } catch (IOException ioe) {
    ioe.printStackTrace();
    return tell();
    // Tells where in the stream we are, adjusted for seeks, resets, skips, etc.
    public long tell () {
    return tellPoint;
    void fatalError (String deathKnell) {
    System.err.println(":[ Fatal Error ]: - " + deathKnell);
    throw new Error(deathKnell);
    ** end file SeekableInputStream.java **
    ** begin file StreamingViewerApplet.java **
    * This Java Applet will take a streaming video passed to it via the applet
    * command in the embedded object and attempt to play it. No fuss, no muss.
    * Based on the SimplePlayerApplet from Sun, and uses a modified version of
    * jicyshout's (jicyshout.sourceforge.net) tweaks to get JMF to play streams.
    * Use it like this:
    * <!-- Sample HTML
    * <APPLET CODE="StreamingViewerApplet.class" WIDTH="320" HEIGHT="240">
    * <PARAM NAME="code" VALUE="StreamingViewerApplet.class">
    * <PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">
    * <PARAM NAME="streamwidth" VALUE="width (defaults to 320, but will resize as per video size)">
    * <PARAM NAME="streamheight" VALUE="height (defaults to 240, but will resize as per video size)">
    * <PARAM NAME="stream" VALUE="insert://your.stream.address.and:port/here/">
    * </APPLET>
    * -->
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.String;
    import java.lang.ArrayIndexOutOfBoundsException;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.net.*;
    import java.io.*;
    import java.io.IOException;
    import java.util.Properties;
    import javax.media.*;
    import javax.media.protocol.*;
    public class StreamingViewerApplet extends Applet implements ControllerListener {
    Player player = null;
    Component visualComponent = null;
    SimpleVideoDataSource dataSource;
    URL url;
    MediaLocator ml;
    Panel panel = null;
    int width = 0;
    static int DEFAULT_VIDEO_WIDTH = 320;
    int height = 0;
    static int DEFAULT_VIDEO_HEIGHT = 240;
    String readParameter = null;
    // Initialize applet, read parameters, create media player.
    public void init () {
    try {
    setLayout(null);
    setBackground(Color.white);
    panel = new Panel();
    panel.setLayout(null);
    add(panel);
    // Attempt to read width from applet parameters. If not given, use default.
    if ((readParameter = getParameter("streamwidth")) == null) {
    width = DEFAULT_VIDEO_WIDTH;
    } else {
    width = Integer.parseInt(readParameter);
    // Ditto for height.
    if ((readParameter = getParameter("streamheight")) == null) {
    height = DEFAULT_VIDEO_HEIGHT;
    } else {
    height = Integer.parseInt(readParameter);
    panel.setBounds(0, 0, width, height);
    // Unfortunately, this we can't default.
    if ((readParameter = getParameter("stream")) == null) {
    fatalError("You must provide a stream parameter!");
    try {
    url = new URL(readParameter);
    ml = new MediaLocator(url);
    dataSource = new SimpleVideoDataSource(ml);
    } catch (MalformedURLException murle) {
    fatalError("Malformed URL Exception: " + murle);
    try {
    dataSource.connect();
    player = Manager.createPlayer(dataSource);
    } catch (IOException ioe) {
    fatalError("IO Exception: " + ioe);
    } catch (NoPlayerException npe) {
    fatalError("No Player Exception: " + npe);
    if (player != null) {
    player.addControllerListener(this);
    } else {
    fatalError("Failed to init() player!");
    } catch (Exception e) {
    fatalError("Error opening player. Details: " + e);
    // Start stream playback. This function is called the
    // first time that the applet runs, and every time the user
    // re-enters the page.
    public void start () {
    try {
    if (player != null) {
    player.realize();
    while (player.getState() != Controller.Realized) {
    Thread.sleep(100);
    // Crashes... here?
    player.start();
    } catch (Exception e) {
    fatalError("Exception thrown: " + e);
    public void stop () {
    if (player != null) {
    player.stop();
    player.deallocate();
    } else {
    fatalError("stop() called on a null player!");
    public void destroy () {
    // player.close();
    // This controllerUpdate function is defined to implement a ControllerListener
    // interface. It will be called whenever there is a media event.
    public synchronized void controllerUpdate(ControllerEvent event) {
    // If the player is dead, just leave.
    if (player == null)
    return;
    // When the player is Realized, get the visual component and add it to the Applet.
    if (event instanceof RealizeCompleteEvent) {
    if (visualComponent == null) {
    if ((visualComponent = player.getVisualComponent()) != null) {
    panel.add(visualComponent);
    Dimension videoSize = visualComponent.getPreferredSize();
    width = videoSize.width;
    height = videoSize.height;
    visualComponent.setBounds(0, 0, width, height);
    } else if (event instanceof CachingControlEvent) {
    // With streaming, this doesn't really matter much, does it?
    // Without, a progress bar of some sort would be appropriate.
    } else if (event instanceof EndOfMediaEvent) {
    // We should never see this... but...
    player.stop();
    fatalError("EndOfMediaEvent reached for streaming media. ewe ewe tea eff?");
    } else if (event instanceof ControllerErrorEvent) {
    player = null;
    fatalError(((ControllerErrorEvent)event).getMessage());
    } else if (event instanceof ControllerClosedEvent) {
    panel.removeAll();
    void fatalError (String deathKnell) {
    System.err.println(":[ Fatal Error ]: - " + deathKnell);
    throw new Error(deathKnell);
    ** end file StreamingViewerApplet.java **
    Now, I'm still new to the JMF, so this might be obvious to some of you... but it's exploding on me, and crashing to desktop (both in IE and Firefox) with some very fun errors:
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x21217921, pid=3200, tid=3160
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
    # Problematic frame:
    # C 0x21217921
    --------------- T H R E A D ---------------
    Current thread (0x058f7280): JavaThread "JMF thread: com.sun.media.amovie.AMController@506411[ com.sun.media.amovie.AMController@506411 ] ( realizeThread)" [_thread_in_native, id=3160]
    siginfo: ExceptionCode=0xc0000005, writing address 0x034e6360
    (plenty more here, I can post the rest if necessary)
    The problem seems to be coming from the "return seekStreams" statement in the first file; when I have execution aborted before that (with a fatalError call), it doesn't crash.
    Any tips/hints/suggestions?

    You should write your own Applet, where you can easily get the visual component (getVisualComponent())and show it directly in your Applet (you call it "embedded"). As far as I know, all examples (AVReceive* etc.) use the component which opens a new window.
    Best regards from Germany,
    r.v.

  • Can't get Sound.close() to work

    Hello Forum,
    I've been trying to use the close() command for the Sound
    class but couldn't get it to work yet.
    Tried playing around with this example script, but the sound
    doesn't want to close:
    http://livedocs.adobe.com/flex/3/langref/flash/media/Sound.html#close()
    I keep getting the following error:
    "Couldn't close stream Error #2029: ~This URLStream-Object
    has no open stream."
    Is the example script broken, or am I doing something wrong?
    Thanks for any help in advance :)

    Judging by all the posts on the forum, there seems to be an issue at Apple's end, although they have made no announcement on their status page. Some users have reported that Apple is aware of the issue. You can leave feedback for Apple at the link below.
    http://www.apple.com/feedback/

  • Deadlock while closing subprocess streams ????

    in my java application i need to run another process and read its streams. I've got a code which:
    1.starts another process using Runtime.exec() method
    2.starts new thread which listen on process input stream
    3.starts new thread which listen on process error stream
    4.starts new thread which waits for new elements in the queue and writes them to process input stream
    5.in some particular situation I need to close that process. I just close streams therefore the process ends.
    The code executed in separate threads for read input and error stream:
         private InputStream fStream;
         private void read() {
              byte[] bytes= new byte[BUFFER_SIZE];
              int read = 0;
              while (read >= 0) {
                   try {
                        read= fStream.read(bytes);
                        if (read > 0) {
                             String text;
                             if (fEncoding != null) {
                                  text = new String(bytes, 0, read, fEncoding);
                             } else {
                                  text = new String(bytes, 0, read);
                             synchronized (this) {
                                  if (isBuffered()) {
                                       fContents.append(text);
                                  fireStreamAppended(text);
                   } catch (IOException ioe) {
                   } catch (NullPointerException e) {
                        return;
         }The code executed in separate thread for writes to process output stream:
          * The stream which is being written to (connected to system in).
         private OutputStream fStream;
          * The queue of output.
         private Vector fQueue;
          * The thread which writes to the stream.
         private Thread fThread;
          * A lock for ensuring that writes to the queue are contiguous
         private Object fLock;
         protected void write() {
              while (fThread != null) {
                   while (!fQueue.isEmpty() && !fClosed) {
                        String text = (String)fQueue.firstElement();
                        fQueue.removeElementAt(0);
                        try {
                             fStream.write(text.getBytes());
                             fStream.flush();
                        } catch (IOException e) {
                             DebugPlugin.log(e);
                   try {
                        synchronized(fLock) {
                             fLock.wait();
                   } catch (InterruptedException e) {
              if (!fClosed) {
                   try {
                       fStream.close();
                   } catch (IOException e) {
                        DebugPlugin.log(e);
         }the problem appears when i asynchronously try close external process by closing its streams:
    inputStream.close()
    errorStrean.close()
    outputStream.close()in this situation it is possible dedlock while closing inputStream when associated thread waits on read() method.
    Also I tried to close output stream first:
    outputStream.close()
    inputStream.close()
    errorStrean.close()but this time it is possible deadlock while closing output stream monitor when associated thread waits on flush() method and external process doesn't read stream.
    I think it is a bug in java because there is no way to close process streams asynchronously. I use java 6 on windows platform

    ejp wrote:
    I just close streams therefore the process ends.No it doesn't. Where did you get that idea from? Closing the output stream might cause the process to end, but you still have to read its input and error streams till EOF in both cases (and then close them - when you have read the EOF in each case).
    Instead of just closing the output stream, you might have to call Process.destroy(). It depends on the process.ok, thank you for the reply. i have modified my code. now i only close output stream. this causes my process to end and thread for reading output and error streams finishes after receiving EOF.
    outputStream.close()but there is still possible deadlock while closing output stream. this because in some cases process i starts doesn't read its input and my thread for writing to output stream waits on flush() method.
    of course it is good idea to use process.destroy() method to cause process to end but it doesn't work for me. the process i start is some kind of launcher which: sets environment, starts another process, redirects streams and finishes itself.. after that i don't have an access to process. i have only streams.
    thanks for your for the replies. i'm afraid that there is no good solution for this kind of problem

  • Streaming Photo

    Hi, I don't know how to remove Photos from i cloud and than from streaming on my ipad2.
    If i close streaming, Photos desappears, but when i want to use it, all the pics i made come back!!
    I can't delate streaming pics from iTunes and also from the folder when iPad is connected to my pc.
    Anyone can help??!!
    Thanx a lot

    Click on Advanced to go to the next window.

  • Is stream closing needed here?

    Is stream closing needed when an object, whose instance variable is a stream, is removed from a Vector?
    I want to be sure whether getting rid of the object also gets rid of the streams, or should I explicitly close the stream before getting rid of the object?
    The following is my situation.
    class MyClass1{
         BufferedReader in;
         PrintWriter out;
    class MyClass2{
         Vector v; //holds MyClass1 objects
    void someMethod(MyClass1 mc1){ // To remove mc1 from Vector.
         v.remove(mc1); // Is this sufficient?
         // Or, should I do as follows?
    //     mc1.in.close();
    //     mc1.out.close();
    //     v.remove(mc1);
         }Thank you.

    You should always expicitly closea stream when you're done using it. And the close call should be inside a finally block so it gets executed even if an exception occurs.
    A stream may or may not be closed for you upon GC, but even if it is, you should never rely on that, as you don't know when or even if it will be GCed.

  • Error in reading the contents of a zip file

    EHello Experts,
    I want to read the contents of a zip file.I have written the following program which reads the contents of a file named "index.xml" which resides in ReadZip.zip.My problem is , it is reading only the first line of that file & after that it is giving this error.
    java.io.IOException: Stream closed
    at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:43)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:67)
    at components.ReadZipFile2.main(ReadZipFile2.java:26)
    public class ReadZipFile2 {
        public static void main(String args[]) {
            try {
                FileInputStream fis = new FileInputStream("C:\\ReadZip.zip");
                ZipInputStream zis = new ZipInputStream(fis);
                ZipEntry ze;
                while ((ze = zis.getNextEntry()) != null) {
                    System.out.println(ze.getName());
                    if (ze.getName().equals("ReadZip/index.xml")) {
                        long size = ze.getSize();
                        if (size > 0) {
                            System.out.println("Length is " + size);
                            BufferedReader br = new BufferedReader(
                                    new InputStreamReader(zis));
                            String line;
                            while ((line = br.readLine()) != null) {
                                System.out.println(line);
                            br.close();
            } catch (IOException e) {
                e.printStackTrace();
    }It seems that zis is getting close after reading the first entry of file.I am unable to guess the reason for this.Please help.Thanx in advance.

    [redacted confused advice]
    [_Compressing and Decompressing Data using Java - with many code samples_|http://java.sun.com/developer/technicalArticles/Programming/compression/|Yes Virginia, there really are code samples]

Maybe you are looking for

  • System no longer sees ix2-dl

    I recently purchased an ix2-dl enclosure and two 2TB WD Red drives.  The initial setup went smoothly and everything was working great using the default RAID1 setup.  After I upgraded the firmware I could not longer use the Lenovo manager utility but

  • Cancellation of Invoice And Taxes

    Hi, SD Gurus Scenario 1 While creating the customer master my client forget to give the account assignment group in the billing tab of the sales area data. Because of this it did not hit the proper G/L Account. Automatically it went to some other  ac

  • How do i enable the job in OWB?

    i have job scheduled in OWB. The job is not automatically kicking off. Here is the status. SQL> select state,enabled from dba_scheduler_jobs where owner='IAEBT_DW' and job_name='PF_JOB'; 2 STATE ENABLED DISABLED FALSE SQL> SQL> EXEC DBMS_SCHEDULER.EN

  • Structural authorisation in HR-PD

    Hi there, Can somebody kindly advise how I can set up the following authorisation in PD. In the Qualification Catalog OOQA, we are giving a display authorisation to the PD administrators to see the entire structure in the qualification master data ca

  • DCP export -very small file..?

    Hello, I'm trying to export a feature film for DCP export and it's been a doozy of an experience so far. I'm using the latest/updated version of Premiere Pro CC, on a MacBook Pro, OS X 10.10.2, 16GB of Ram.  The film is 84mins total, shot on a RED My