Solved

about ServletOutputStream

Posted on 2001-07-03
9
1,167 Views
Last Modified: 2008-02-07
in my servlet i am writing some data on SetvletOutputStream.Before reaching to the client i want to modify some data which i wrote on outputstream.How i can read the data from ServletOutputStream and manipulate it??
0
Comment
Question by:manojvelliyatt
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:Prasanna_Hebbar
Comment Utility
Can't you modify the data before writing into ServletOutputStream and then write it into output stream?

If that is not possible, the other solution will be to do write another servlet. This servlet gets the result from the main servlet and modifies the data and writes the data into its output stream. The client program now instead of using the main servlet, use this secondary servlet.

Again can you be more clear on your intent? Instead of going for the above approach, where there is one more layer, there might be a simple and cleaner solution. Like you can write a class at the client side to modify the data.

More explanation please.....
0
 
LVL 2

Expert Comment

by:Andrey_Kulik
Comment Utility
Hi
in your case you could create ProxyOutputStream. This Stream will flush their content to the real ServletOutputStream after all changes during work with data.

Andrey
0
 
LVL 4

Accepted Solution

by:
omry_y earned 200 total points
Comment Utility
just write your output to a ByteArrayOutputStream insead of to the ServletOutputStream, get the bytes array, manipulate it(you can read it easly using ByteArrayInputStream), and than write the resulting byte array to the ServletOutputStream.
0
 
LVL 2

Expert Comment

by:Andrey_Kulik
Comment Utility
omry_y : it's the same :)

Best regards
Andrey
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 4

Expert Comment

by:omry_y
Comment Utility
well, not exactly.
you can`t really manipulate stuff inside an output stream.
(not even a proxy output stream).
you will to get the data in another form, either a byte array, or an input stream.

0
 

Author Comment

by:manojvelliyatt
Comment Utility
omry_y,
how i can convet my ServletOutputStream to ByteArrayOutputStream i don't think that is possible.it will throw a class cast exception at run time.
just check it out and tell me the result.

Andrey_Kulik,
what is this ProxyOutputStream?
do you mean i have to write a proxy server,and communicate to my servlet.

0
 
LVL 2

Expert Comment

by:Prasanna_Hebbar
Comment Utility
manoj,

Whatever omry_y has suggested is the change in the servlet. Instead of writing the data into servlet output stream, he is suggesting you to write the data into a bytearrayoutputstream. Then modify the data from bytearrayoutputstream and write it into servlet output stream.

This is much similar to what I suggested. ie modify the data before writing the data into servlet. I don't think you need to have bytearrayoutputstream if you are ready to modify the data in the servlet. Why you should write the data into a bytearrayoutputstream, instead you can store the data in a string. Modify this string, and latter write it into servlet output stream.

Again, can you be more clear on your question? Are you ready to modify the code in the servlet? Or do you want to put one more layer?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to Prasanna_Hebbar]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0
 
LVL 4

Expert Comment

by:omry_y
Comment Utility
I think Prasanna_Hebbar and I both suggested valid solutions.
mine means changing the code, but leaving the configuration the same.
Prasanna_Hebbar means leaving the code the same, but changing the configuration.

I therefor think the points should be splited between us.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now