Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

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

 
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22753
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ramakanta Sahoo
Ranch Hand
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


somebody help me
 
Rob Spoor
Sheriff
Posts: 22753
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/PatienceIsAVirtue

And never ever ever use that many smilies in one place again. Ugh!
 
Rob Spoor
Sheriff
Posts: 22753
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22753
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 256
Netbeans IDE Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22753
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic