Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

about ServletOutputStream

Posted on 2001-07-03
9
Medium Priority
?
1,183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:Prasanna_Hebbar
ID: 6251437
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
ID: 6252563
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 400 total points
ID: 6253075
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:Andrey_Kulik
ID: 6253179
omry_y : it's the same :)

Best regards
Andrey
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6253208
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
ID: 6254188
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
ID: 6254301
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
ID: 9017937
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
ID: 9018346
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

636 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