This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Read and Write PDF file using RandomAccessFile class

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am new to this API. I have a doubt from RandomAccessFile. Can anyone tell me that, how to read and write PDF files using RandomAccessFile class. Otherwise I need to use any third party APIs.

Thanks in advance.

Regards,
Prabhakaran
 
Marshal
Posts: 26536
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you want to do that?

And yes, you don't have to use any 3rd-party code if you want to learn and implement the PDF specification yourself. But I wouldn't recommend that unless you have a couple of months with nothing else to do. Using the 3rd-party code is a much better idea.

And why are RandomAccessFile and 3rd-party APIs the only two alternatives?
 
Natesan Prabhakaran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

I am sending PDF (other formats also)file using UDP. If while missing some packets, I need to send back missing packets and write it into PDF file. But PDF format is somehow distrubing to do that.

Also, can you suggest better third-party API for it.

-Prabhakaran
 
Sheriff
Posts: 22155
117
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
UDP makes absolutely no guarantees for any packet arriving safely, so it should not be used for file transfers. Why did you decide to use UDP over TCP in the first place?
 
Natesan Prabhakaran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But compare to UDP, TCP will take much time to transfer a very large file and huge amount of files at a time. Thats the reason, I go with UDP.
 
Paul Clapham
Marshal
Posts: 26536
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't care about receiving the whole file, an even faster method is to just not send it at all. Takes zero time, it isn't especially accurate but it's really really fast.

Seriously, like Rob said, don't use UDP.

And how did this question get to be about transmitting data, when your original post was about random access files and products for producing PDF files?
 
Natesan Prabhakaran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot paul.

That’s the reason why, if any packets missed out, I request for missing packets. Then, by using RandomAccessFile, need to send back the missing data only. Also, I want to write it into PDF file in the receiving end.

So, Please tell me, is there any possibility to write on PDF by using RandaomAccessFile, else suggest me an idea.

- Prabhakaran
 
Ranch Hand
Posts: 168
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Natesan Prabhakaran wrote:
So, Please tell me, is there any possibility to write on PDF by using RandaomAccessFile


Yes, you can read and write any kind of files using RandomAccessFile. However, if you want to create a PDF file from a string or a text file, you need a Java PDF library. Search in Google using "Java PDF Library" as the keywords.

Regarding using UDP instead of TCP, is it your decision or someone else's (your boss/software architect/team leader)? If it is your own decision, you should re-consider it. Using UDP, not only that you may loss some of the packets, the receiver may receive the packet in a wrong order. And you may receive a single packet twice. Your program must be able to handle these kinds of situation.

There are a lot of articles in the internet about the pros and cons of TCP and UDP. You should read them.
 
Rob Spoor
Sheriff
Posts: 22155
117
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
Yosi is right. It is TCP that does all this for you. That's also why it is slower; it sends acknowledgements back to the sender to indicate a packet has been received correctly. That's also something you would need to do. You can't assume you've missed a packet because the following packet has arrived. You can wait until you've received the last packet and then request the missing pieces, but what if this last packet never arrives?

Seriously, use TCP. It will do all the hard work for you.
 
Paul Clapham
Marshal
Posts: 26536
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Natesan Prabhakaran wrote:Thanks a lot paul.

That’s the reason why, if any packets missed out, I request for missing packets. Then, by using RandomAccessFile, need to send back the missing data only. Also, I want to write it into PDF file in the receiving end.

So, Please tell me, is there any possibility to write on PDF by using RandaomAccessFile, else suggest me an idea.



I don't understand why you think that writing to a file with a RandomAccessFile object is somehow going to re-send missing UDP packets. Where on earth did you get that idea from?

Possibly you could receive the missing packets and update the file on the receiving end with a RandomAccessFile object, if you really kept track of the packets which were received and had some way of identifying the ones which weren't received. But trying to make a reliable protocol out of UDP is pointless when you already have TCP to use. You can wave your hands about speed all you like but you aren't going to be able to make a reliable layer over UDP which is better than TCP.
reply
    Bookmark Topic Watch Topic
  • New Topic