Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

cs.getOutputStream() called 2 times or more

Posted on 2006-05-01
6
Medium Priority
?
208 Views
Last Modified: 2010-03-31
Assume I have server S, client C. These following code is executed in server:
ServerSocket ss = new ServerSocket(1234);
Socket cs = ss.accept();
PrintWriter out1 = new PrintWriter(cs.getOutputStream(),true);
PrintWriter out2 = new PrintWriter(cs.getOutputStream(),true);
My question is, is out1 = out2. For example, when I run out2.close(), is out1 closed?
And a small question, when the application exits without calling out1.close() before, is out1 closed automatically when the application exited?
0
Comment
Question by:maidinhtai
  • 4
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16580076
>>My question is, is out1 = out2.

No. Why do you need two PrintWriter opened?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16580084
>>is out1 closed automatically when the application

That can't be assumed. Close resources in finally blocks
0
 
LVL 3

Author Comment

by:maidinhtai
ID: 16580282
When I run out2.close(), is out1 closed? I has the problem here.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Accepted Solution

by:
CEHJ earned 1200 total points
ID: 16580819
No. The underlying stream is closed
0
 
LVL 92

Assisted Solution

by:objects
objects earned 800 total points
ID: 16581245
> My question is, is out1 = out2.

No, they are different writers. But they both wrap the same underlying stream

> For example, when I run out2.close(), is out1 closed?

out1 isn't closed, but as CEHJ mentiuoned the wrapped stream is.

> when the application exits without calling out1.close() before, is out1 closed automatically when the application exited?

yes


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16584118
:-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

564 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