aspose file tools*
The moose likes Java in General and the fly likes Is there any free libraries avaialble for file splitting usiong java?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is there any free libraries avaialble for file splitting usiong java??" Watch "Is there any free libraries avaialble for file splitting usiong java??" New topic
Author

Is there any free libraries avaialble for file splitting usiong java??

Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi All,

I want to split a file of 10GB or so into ten 1GB files using java. Is there any freeware reliable libraries are available then please point me to there.


Regards, Ricky
Oracle Weblogic 10g Certified Expert TechPaste.Com
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

How about the core API, with FileInputStream and FileOutputStream? Read from the FileInputStream and copy to the FileOutputStream. Then, when you've written 1GB, close the FileOutputStream and open a new one.

Pasting them together is similar. Copy all contents from the FileInputStream to the FileOutputStream. Then, when the FileInputStream has been read, close it and open the next one, writing to the same FileOutputStream.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi Thanks,

The program is like below but it hangs when ever i want to split any file of 2gb or beyond.Even if the folder am not able to do a ls -ltr after running the splitme pro.
I know something is foolishly wrong can somebody please take a look at it.




Thanks,
-Ricky>
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254



somebody help me
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

http://faq.javaranch.com/java/PatienceIsAVirtue

And never ever ever use that many smilies in one place again. Ugh!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

2GB is 2 * 1024 * 1024* 1024 bytes = 2,147,483,648 bytes. Integer.MAX_VALUE is 2,147,483,647, one smaller. So when you read the long value and cast it to int, it will wrap around and become -2,147,483,648 instead. As such, the check "leng<splitlen" will never be true, the inner while loop will never execute and you never read any data anymore. As a result, data will keep the value of the first byte forever.

Instead of limiting your splitlen to int, make it long. Also, disallow negative values; if someone types in -1 the same will occur.>
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Thanks Rob,

Sorry for too many similes. I changed to long its working but the speed of splitting is very slow almost takes 3 and 1/2hrs to split a 3GB file in 2GB slices.
Is there anything I can do to make it faster. Any suggestions for Better performance??
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi All,

Does somebody knows how i will be able to tweak the program for optimal performance.

Now its taking 3hr:30mins to split a 3GB file into 2GB slices.

Please give your valuable suggestions


Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Switch from RandomAccessFile to InputStream and OutputStream, then use BufferedInputStream and BufferedOutputStream. So your code changes as this (leaving out unchanged code):
Since InputStream and OutputStream also have the read() / write() and close() methods that should cause your code to compile without any problems.
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Thanks, noe its much faster than before.

1 Question What is the major difference between RandomAccess and InputStream ?? Why so much of performance diff ??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

I don't know if it is the InputStream that is making the difference; I think it's the BufferedInputStream. The RandomAccessFile really reads one byte at a time, whereas the BufferedInputStream reads chunks of multiple bytes, even if you only call the read() method that returns one byte. Reading multiple bytes (usually entire "pages" of several kilobytes) is usually much more efficient.
 
Don't get me started about those stupid light bulbs.
 
subject: Is there any free libraries avaialble for file splitting usiong java??