Bad File Descriptor Error In Java
Contents |
This Site Careers Other all forums Forum: I/O and Streams FileInputStream Exception - Bad file descriptor David Law Greenhorn Posts: 2 posted 9 years ago Hi. java io ioexception bad file descriptor I am trying to learn about compression and have fallen at the bad file descriptor error in c first hurdle. The following code gzip's files: import java.io.*; import java.util.zip.*; public class Compressor { public static
Write Error Bad File Descriptor
void gzipFile(String srcFileName, String destFileName) throws IOException { FileInputStream fis = new FileInputStream(srcFileName); FileOutputStream fos = new FileOutputStream(destFileName); GZIPOutputStream gzipOut = new GZIPOutputStream(fos); byte[] buf = new byte[4096]; int
Socket Error Bad File Descriptor
bytesRead; while((bytesRead = fis.read(buf)) != -1) { gzipOut.write(buf, 0, bytesRead); fis.close(); gzipOut.close(); } } public static void main(String[] args) throws IOException { String src = args[0]; String dest = src + ".gz"; Compressor.gzipFile(src, dest); } } ... but I get the following errors: Exception in thread "main" java.io.IOException: Bad file descriptor at java.io.FileInputStream.readBytes(Native Method) at java.io.FileInputStream.read(FileInputStream.java:177) at Compressor.gzipFile(Compressor.java:16) bad file descriptor python at Compressor.main(Compressor.java:28) One site I visited said it was a bug in Java but the code wasn't quite the same. If anyone could point me in the right direction I'd be very grateful. Thank you. BTW I am using jdk 1.6 on Linux. Freddy Wong Ranch Hand Posts: 959 I like... posted 9 years ago I don't think it's a bug in Java. while((bytesRead = fis.read(buf)) != -1) { gzipOut.write(buf, 0, bytesRead); fis.close(); gzipOut.close(); } Shouldn't it be like something like this: while((bytesRead = fis.read(buf)) != -1) { gzipOut.write(buf, 0, bytesRead); } fis.close(); gzipOut.close(); SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4 My Blog David Law Greenhorn Posts: 2 posted 9 years ago Ahhhhh of course. Thank you very much Freddy! Post Reply Bookmark Topic Watch Topic New Topic Similar Threads Copying Multiple Files Over A Socket Urgent ! Sending a file over socket Copy file Compressing and Decompressing strings in Java All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter Contact Us | advertise | mobil
This Site Careers Other all forums Forum: bad file descriptor perl I/O and Streams java.io.IOException: Bad file descriptor Amirr Rafique Ranch Hand https://coderanch.com/t/278598/java-io/java/FileInputStream-Exception-Bad-file-descriptor Posts: 324 posted 7 years ago Hi mates While reading a FileInputStream I am experiencing following exception. Please help me to identify the reason java.io.IOException: https://coderanch.com/t/441182/java-io/java/java-io-IOException-Bad-file Bad file descriptor at java.io.FileInputStream.readBytes(Native Method) at java.io.FileInputStream.read(Unknown Source) at java.io.DataInputStream.read(Unknown Source) at logic.ICCSChequeImagesReport.downloadChequeImagesFromDocumentServer(ICCSChequeImagesReport.java:337) at logic.ICCSChequeImagesReport.extractChequeImages(ICCSChequeImagesReport.java:303) at logic.ICCSChequeImagesReport.extract(ICCSChequeImagesReport.java:292) at logic.ICCSChequeImagesReport.
it was our buggy software to blame, a closer look at the problem seems to point elsewhere. Our current research seems to indicate that a bug in Sun's JDK under Linux (maybe others) is at fault here. Background We have been seeing a http://256stuff.com/gray/docs/misc/java_bad_file_descriptor_close_bug.shtml large number of the 'Bad file descriptor' exceptions in various places around our software. We initially thought that we were someone double closing or otherwise improperly using file handles. However, after a more aggressively review of the code in question as http://www-10.lotus.com/ldd/portalwiki.nsf/dx/Resolving_the_following_error_java.io.IOException_Bad_file_descriptorThe_handle_is_invalid_bnk_1.0.0 well as the JDK, we came to the conclusion that aside from creating input or output streams using the FileDescriptor constructor (which we were not doing) there should be no way to get these problems. In addition, many of the bad file places which were throwing the exceptions (see below) were in 3rd party libraries including Lucene and Berkeley Database JE. Our application is a search system which is using ActiveMQ JMS to receive, index, and store documents. We use 10s of JMS queues and topics to coordinate a distributed collection of search nodes. This translates into 10s of sockets which are mostly TCP but some UDP and multicast packets. Local disk descriptors to standard SCSI disks or hardware/software raid configurations. No bad file descriptor network filesystems are being used. Mostly EXT3, some XFS, and Some temporary filesystems but otherwise nothing exotic. Possible Solution In November 2007, a guy sent me mail mentioning that they had experiences the same problem with their software. After much work with their Sun support contract, the bug has been fixed. Here's the Sun bug database entry. It states that the fix will be in Java 1.5u14 and 1.6u4. To quote: When a close() operation on an OS file descriptor is succesful, the record of the FD is set to -1, and on subsequent close() operations the actual call to the OS' close() is not performed. If an error occurs in the OS' close(), we do not set our record of the FD to -1, so subsequent calls will re-attempt the close(). We should not re-attempt the close(). As of February 26, 2007, more testing has revealed that our problems seem to be coming from concurrency issues in Sun's 1.5 JDK (through v.11) combined with Lucene v2.0's calling close() in FSIndexInput.finalize() and FSIndexOutput.finalize() methods -- a real no-no. Looks like v2.1 has 2 bug fixes that would resolve this (669 and 750). We think that the problem is a race condition between a user thread which has caused close and the finalizer which is also calling close. The fact that the FileDescriptor has already been closed is not properly synchronized between the 2 threads so a double close is perfo
category IBM Redbooks: Building a Sample Website Using IBM Web Content Manager 7.0 IBM Redbooks: Building and Implementing a Social Portal IBM Redbooks: Building and Implementing Social Digital Experiences IBM Redbooks: Developing Exceptional Multi-Channel Web Experiences V7: IBM Web Content Manager Product Documentation V7: IBM WebSphere Portal Enable for z/OS Product Documentation V7: IBM WebSphere Portal Express Product Documentation V7: WebSphere Portal Product Documentation V8: IBM Web Content Manager Product Documentation V8: IBM WebSphere Portal Express Product Documentation V8: IBM WebSphere Portal Product Documentation (includes z/OS) Custom Search Scope... Search Share ▼ Subscribe ▼ Share ▼ Subscribe ▼ IBM Banking TemplateSelect version 1.0.0 2.0.0 3.0.0 IBM Banking template for WebSphere Portal