2002-09-11 Michael Koch <konqueror@gmx.de>
[gcc.git] / libjava / java / net / Socket.java
1 /* Socket.java -- Client socket implementation
2 Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
37
38 package java.net;
39
40 import java.io.*;
41
42 /* Written using on-line Java Platform 1.2 API Specification.
43 * Status: I believe all methods are implemented.
44 */
45
46 /**
47 * This class models a client site socket. A socket is a TCP/IP endpoint
48 * for network communications conceptually similar to a file handle.
49 * <p>
50 * This class does not actually do any work. Instead, it redirects all of
51 * its calls to a socket implementation object which implements the
52 * <code>SocketImpl</code> interface. The implementation class is
53 * instantiated by factory class that implements the
54 * <code>SocketImplFactory interface</code>. A default
55 * factory is provided, however the factory may be set by a call to
56 * the <code>setSocketImplFactory</code> method. Note that this may only be
57 * done once per virtual machine. If a subsequent attempt is made to set the
58 * factory, a <code>SocketException</code> will be thrown.
59 *
60 * @author Aaron M. Renn (arenn@urbanophile.com)
61 * @author Per Bothner (bothner@cygnus.com)
62 */
63 public class Socket
64 {
65
66 // Class Variables
67
68 /**
69 * This is the user SocketImplFactory for this class. If this variable is
70 * null, a default factory is used.
71 */
72 static SocketImplFactory factory;
73
74 // Instance Variables
75
76 /**
77 * The implementation object to which calls are redirected
78 */
79 SocketImpl impl;
80
81 // Constructors
82
83 /**
84 * Initializes a new instance of <code>Socket</code> object without
85 * connecting to a remote host. This useful for subclasses of socket that
86 * might want this behavior.
87 *
88 * @specnote This constructor is public since JDK 1.4
89 */
90 public Socket ()
91 {
92 if (factory != null)
93 impl = factory.createSocketImpl();
94 else
95 impl = new PlainSocketImpl();
96 }
97
98 /**
99 * Initializes a new instance of <code>Socket</code> object without
100 * connecting to a remote host. This is useful for subclasses of socket
101 * that might want this behavior.
102 * <p>
103 * Additionally, this socket will be created using the supplied
104 * implementation class instead the default class or one returned by a
105 * factory. This value can be <code>null</code>, but if it is, all instance
106 * methods in <code>Socket</code> should be overridden because most of them
107 * rely on this value being populated.
108 *
109 * @param impl The <code>SocketImpl</code> to use for this
110 * <code>Socket</code>
111 *
112 * @exception SocketException If an error occurs
113 */
114 protected Socket (SocketImpl impl) throws SocketException
115 {
116 this.impl = impl;
117 }
118
119 /**
120 * Initializes a new instance of <code>Socket</code> and connects to the
121 * hostname and port specified as arguments.
122 *
123 * @param host The name of the host to connect to
124 * @param port The port number to connect to
125 *
126 * @exception UnknownHostException If the hostname cannot be resolved to a
127 * network address.
128 * @exception IOException If an error occurs
129 */
130 public Socket (String host, int port)
131 throws UnknownHostException, IOException
132 {
133 this(InetAddress.getByName(host), port, null, 0, true);
134 }
135
136 /**
137 * Initializes a new instance of <code>Socket</code> and connects to the
138 * address and port number specified as arguments.
139 *
140 * @param address The address to connect to
141 * @param port The port number to connect to
142 *
143 * @exception IOException If an error occurs
144 */
145 public Socket (InetAddress address, int port)
146 throws IOException
147 {
148 this(address, port, null, 0, true);
149 }
150
151 /**
152 * Initializes a new instance of <code>Socket</code> that connects to the
153 * named host on the specified port and binds to the specified local address
154 * and port.
155 *
156 * @param host The name of the remote host to connect to.
157 * @param port The remote port to connect to.
158 * @param loadAddr The local address to bind to.
159 * @param localPort The local port to bind to.
160 *
161 * @exception SecurityException If the <code>SecurityManager</code>
162 * exists and does not allow a connection to the specified host/port or
163 * binding to the specified local host/port.
164 * @exception IOException If a connection error occurs.
165 */
166 public Socket (String host, int port,
167 InetAddress localAddr, int localPort) throws IOException
168 {
169 this(InetAddress.getByName(host), port, localAddr, localPort, true);
170 }
171
172 /**
173 * Initializes a new instance of <code>Socket</code> and connects to the
174 * address and port number specified as arguments, plus binds to the
175 * specified local address and port.
176 *
177 * @param address The remote address to connect to
178 * @param port The remote port to connect to
179 * @param localAddr The local address to connect to
180 * @param localPort The local port to connect to
181 *
182 * @exception IOException If an error occurs
183 */
184 public Socket (InetAddress address, int port,
185 InetAddress localAddr, int localPort) throws IOException
186 {
187 this(address, port, localAddr, localPort, true);
188 }
189
190 /**
191 * Initializes a new instance of <code>Socket</code> and connects to the
192 * hostname and port specified as arguments. If the stream argument is set
193 * to <code>true</code>, then a stream socket is created. If it is
194 * <code>false</code>, a datagram socket is created.
195 *
196 * @param host The name of the host to connect to
197 * @param port The port to connect to
198 * @param stream <code>true</code> for a stream socket, <code>false</code>
199 * for a datagram socket
200 *
201 * @exception IOException If an error occurs
202 *
203 * @deprecated Use the <code>DatagramSocket</code> class to create
204 * datagram oriented sockets.
205 */
206 public Socket (String host, int port, boolean stream) throws IOException
207 {
208 this(InetAddress.getByName(host), port, null, 0, stream);
209 }
210
211 /**
212 * Initializes a new instance of <code>Socket</code> and connects to the
213 * address and port number specified as arguments. If the stream param is
214 * <code>true</code>, a stream socket will be created, otherwise a datagram
215 * socket is created.
216 *
217 * @param host The address to connect to
218 * @param port The port number to connect to
219 * @param stream <code>true</code> to create a stream socket,
220 * <code>false</code> to create a datagram socket.
221 *
222 * @exception IOException If an error occurs
223 *
224 * @deprecated Use the <code>DatagramSocket</code> class to create
225 * datagram oriented sockets.
226 */
227 public Socket (InetAddress host, int port, boolean stream) throws IOException
228 {
229 this(host, port, null, 0, stream);
230 }
231
232 /**
233 * This constructor is where the real work takes place. Connect to the
234 * specified address and port. Use default local values if not specified,
235 * otherwise use the local host and port passed in. Create as stream or
236 * datagram based on "stream" argument.
237 * <p>
238 *
239 * @param raddr The remote address to connect to
240 * @param rport The remote port to connect to
241 * @param laddr The local address to connect to
242 * @param lport The local port to connect to
243 * @param stream true for a stream socket, false for a datagram socket
244 *
245 * @exception IOException If an error occurs
246 */
247 private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport,
248 boolean stream) throws IOException
249 {
250 this();
251 if (impl == null)
252 throw new IOException("Cannot initialize Socket implementation");
253
254 SecurityManager sm = System.getSecurityManager();
255 if (sm != null)
256 sm.checkConnect(raddr.getHostName(), rport);
257
258 impl.create(stream);
259
260 // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
261 // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
262 // that default. JDK 1.2 doc infers not to do a bind.
263 if (laddr != null)
264 impl.bind(laddr, lport);
265
266 if (raddr != null)
267 impl.connect(raddr, rport);
268 }
269
270 /**
271 * Binds the socket to the givent local address/port
272 *
273 * @param bindpoint The address/port to bind to
274 *
275 * @exception If an error occurs
276 *
277 * @since 1.4
278 */
279 public void bind (SocketAddress bindpoint) throws IOException
280 {
281 if ( !(bindpoint instanceof InetSocketAddress))
282 throw new IllegalArgumentException ();
283
284 InetSocketAddress tmp = (InetSocketAddress) bindpoint;
285 impl.bind (tmp.getAddress(), tmp.getPort());
286 }
287
288 /**
289 * Connects the socket with a remote address.
290 *
291 * @param endpoint The address to connect to
292 *
293 * @exception IOException If an error occurs
294 *
295 * @since 1.4
296 */
297 public void connect (SocketAddress endpoint)
298 throws IOException
299 {
300 impl.connect (endpoint, 0);
301 }
302
303 /**
304 * Connects the socket with a remote address. A timeout of zero is
305 * interpreted as an infinite timeout. The connection will then block
306 * until established or an error occurs.
307 *
308 * @param endpoint The address to connect to
309 *
310 * @exception IOException If an error occurs
311 *
312 * @since 1.4
313 */
314 public void connect (SocketAddress endpoint, int timeout)
315 throws IOException
316 {
317 impl.connect (endpoint, timeout);
318 }
319
320 /**
321 * Returns the address of the remote end of the socket. If this socket
322 * is not connected, then <code>null</code> is returned.
323 *
324 * @return The remote address this socket is connected to
325 */
326 public InetAddress getInetAddress ()
327 {
328 if (impl != null)
329 return impl.getInetAddress();
330
331 return null;
332 }
333
334 /**
335 * Returns the local address to which this socket is bound. If this socket
336 * is not connected, then <code>null</code> is returned.
337 *
338 * @return The local address
339 */
340 public InetAddress getLocalAddress ()
341 {
342 if (impl == null)
343 return null;
344
345 InetAddress addr = null;
346 try
347 {
348 addr = (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
349 }
350 catch(SocketException e)
351 {
352 // (hopefully) shouldn't happen
353 // throw new java.lang.InternalError
354 // ("Error in PlainSocketImpl.getOption");
355 return null;
356 }
357
358 // FIXME: According to libgcj, checkConnect() is supposed to be called
359 // before performing this operation. Problems: 1) We don't have the
360 // addr until after we do it, so we do a post check. 2). The docs I
361 // see don't require this in the Socket case, only DatagramSocket, but
362 // we'll assume they mean both.
363 SecurityManager sm = System.getSecurityManager();
364 if (sm != null)
365 sm.checkConnect(addr.getHostName(), getLocalPort());
366
367 return addr;
368 }
369
370 /**
371 * Returns the port number of the remote end of the socket connection. If
372 * this socket is not connected, then -1 is returned.
373 *
374 * @return The remote port this socket is connected to
375 */
376 public int getPort ()
377 {
378 if (impl != null)
379 return impl.getPort();
380
381 return -1;
382 }
383
384 /**
385 * Returns the local port number to which this socket is bound. If this
386 * socket is not connected, then -1 is returned.
387 *
388 * @return The local port
389 */
390 public int getLocalPort ()
391 {
392 if (impl != null)
393 return impl.getLocalPort();
394
395 return -1;
396 }
397
398 /**
399 * Returns an InputStream for reading from this socket.
400 *
401 * @return The InputStream object
402 *
403 * @exception IOException If an error occurs or Socket is not connected
404 */
405 public InputStream getInputStream () throws IOException
406 {
407 if (impl != null)
408 return(impl.getInputStream());
409
410 throw new IOException("Not connected");
411 }
412
413 /**
414 * Returns an OutputStream for writing to this socket.
415 *
416 * @return The OutputStream object
417 *
418 * @exception IOException If an error occurs or Socket is not connected
419 */
420 public OutputStream getOutputStream () throws IOException
421 {
422 if (impl != null)
423 return impl.getOutputStream();
424
425 throw new IOException("Not connected");
426 }
427
428 /**
429 * Sets the TCP_NODELAY option on the socket.
430 *
431 * @param on true to enable, false to disable
432 *
433 * @exception SocketException If an error occurs or Socket is not connected
434 */
435 public void setTcpNoDelay (boolean on) throws SocketException
436 {
437 if (impl == null)
438 throw new SocketException("Not connected");
439
440 impl.setOption(SocketOptions.TCP_NODELAY, new Boolean(on));
441 }
442
443 /**
444 * Tests whether or not the TCP_NODELAY option is set on the socket.
445 * Returns true if enabled, false if disabled. When on it disables the
446 * Nagle algorithm which means that packets are always send immediatly and
447 * never merged together to reduce network trafic.
448 *
449 * @return Whether or not TCP_NODELAY is set
450 *
451 * @exception SocketException If an error occurs or Socket not connected
452 */
453 public boolean getTcpNoDelay() throws SocketException
454 {
455 if (impl == null)
456 throw new SocketException("Not connected");
457
458 Object on = impl.getOption(SocketOptions.TCP_NODELAY);
459
460 if (on instanceof Boolean)
461 return(((Boolean)on).booleanValue());
462 else
463 throw new SocketException("Internal Error");
464 }
465
466 /**
467 * Sets the value of the SO_LINGER option on the socket. If the
468 * SO_LINGER option is set on a socket and there is still data waiting to
469 * be sent when the socket is closed, then the close operation will block
470 * until either that data is delivered or until the timeout period
471 * expires. The linger interval is specified in hundreths of a second
472 * (platform specific?)
473 *
474 * @param on true to enable SO_LINGER, false to disable
475 * @param linger The SO_LINGER timeout in hundreths of a second or -1 if
476 * SO_LINGER not set.
477 *
478 * @exception SocketException If an error occurs or Socket not connected
479 */
480 public void setSoLinger(boolean on, int linger) throws SocketException
481 {
482 if (impl == null)
483 throw new SocketException("No socket created");
484
485 if (on == true)
486 {
487 if (linger < 0)
488 throw new IllegalArgumentException("SO_LINGER must be >= 0");
489
490 if (linger > 65535)
491 linger = 65535;
492
493 impl.setOption(SocketOptions.SO_LINGER, new Integer(linger));
494 }
495 else
496 {
497 impl.setOption(SocketOptions.SO_LINGER, new Boolean(false));
498 }
499 }
500
501 /**
502 * Returns the value of the SO_LINGER option on the socket. If the
503 * SO_LINGER option is set on a socket and there is still data waiting to
504 * be sent when the socket is closed, then the close operation will block
505 * until either that data is delivered or until the timeout period
506 * expires. This method either returns the timeouts (in hundredths of
507 * of a second (platform specific?)) if SO_LINGER is set, or -1 if
508 * SO_LINGER is not set.
509 *
510 * @return The SO_LINGER timeout in hundreths of a second or -1
511 * if SO_LINGER not set
512 *
513 * @exception SocketException If an error occurs or Socket is not connected
514 */
515 public int getSoLinger() throws SocketException
516 {
517 if (impl == null)
518 throw new SocketException("Not connected");
519
520 Object linger = impl.getOption(SocketOptions.SO_LINGER);
521 if (linger instanceof Integer)
522 return(((Integer)linger).intValue());
523 else
524 return -1;
525 }
526
527 /**
528 * Enables/disables the SO_OOBINLINE option
529 *
530 * @param on True if SO_OOBLINE should be enabled
531 *
532 * @exception SocketException If an error occurs
533 *
534 * @since 1.4
535 */
536 public void setOOBInline (boolean on) throws SocketException
537 {
538 if (impl == null)
539 throw new SocketException("Not connected");
540
541 impl.setOption(SocketOptions.SO_OOBINLINE, new Boolean(on));
542 }
543
544 /**
545 * Returns the current setting of the SO_OOBINLINE option for this socket
546 *
547 * @exception SocketException If an error occurs
548 *
549 * @since 1.4
550 */
551 public boolean getOOBInline () throws SocketException
552 {
553 if (impl == null)
554 throw new SocketException("Not connected");
555
556 Object buf = impl.getOption(SocketOptions.SO_OOBINLINE);
557
558 if (buf instanceof Boolean)
559 return(((Boolean)buf).booleanValue());
560 else
561 throw new SocketException("Internal Error: Unexpected type");
562 }
563
564 /**
565 * Sets the value of the SO_TIMEOUT option on the socket. If this value
566 * is set, and an read/write is performed that does not complete within
567 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
568 * would be sent in Unix if no data had been read). A value of 0 for
569 * this option implies that there is no timeout (ie, operations will
570 * block forever). On systems that have separate read and write timeout
571 * values, this method returns the read timeout. This
572 * value is in thousandths of a second (****????*****)
573 *
574 * @param timeout The length of the timeout in thousandth's of a second or
575 * 0 if not set
576 *
577 * @exception SocketException If an error occurs or Socket not connected
578 */
579 public synchronized void setSoTimeout (int timeout) throws SocketException
580 {
581 if (impl == null)
582 throw new SocketException("Not connected");
583
584 if (timeout < 0)
585 throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
586
587 impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
588 }
589
590 /**
591 * Returns the value of the SO_TIMEOUT option on the socket. If this value
592 * is set, and an read/write is performed that does not complete within
593 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
594 * would be sent in Unix if no data had been read). A value of 0 for
595 * this option implies that there is no timeout (ie, operations will
596 * block forever). On systems that have separate read and write timeout
597 * values, this method returns the read timeout. This
598 * value is in thousandths of a second (implementation specific?).
599 *
600 * @return The length of the timeout in thousandth's of a second or 0
601 * if not set
602 *
603 * @exception SocketException If an error occurs or Socket not connected
604 */
605 public synchronized int getSoTimeout () throws SocketException
606 {
607 if (impl == null)
608 throw new SocketException("Not connected");
609
610 Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
611 if (timeout instanceof Integer)
612 return(((Integer)timeout).intValue());
613 else
614 return 0;
615 }
616
617 /**
618 * This method sets the value for the system level socket option
619 * SO_SNDBUF to the specified value. Note that valid values for this
620 * option are specific to a given operating system.
621 *
622 * @param size The new send buffer size.
623 *
624 * @exception SocketException If an error occurs or Socket not connected
625 *
626 * @since 1.2
627 */
628 public void setSendBufferSize (int size) throws SocketException
629 {
630 if (impl == null)
631 throw new SocketException("Not connected");
632
633 if (size <= 0)
634 throw new IllegalArgumentException("SO_SNDBUF value must be > 0");
635
636 impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
637 }
638
639 /**
640 * This method returns the value of the system level socket option
641 * SO_SNDBUF, which is used by the operating system to tune buffer
642 * sizes for data transfers.
643 *
644 * @return The send buffer size.
645 *
646 * @exception SocketException If an error occurs or socket not connected
647 *
648 * @since 1.2
649 */
650 public int getSendBufferSize () throws SocketException
651 {
652 if (impl == null)
653 throw new SocketException("Not connected");
654
655 Object buf = impl.getOption(SocketOptions.SO_SNDBUF);
656
657 if (buf instanceof Integer)
658 return(((Integer)buf).intValue());
659 else
660 throw new SocketException("Internal Error: Unexpected type");
661 }
662
663 /**
664 * This method sets the value for the system level socket option
665 * SO_RCVBUF to the specified value. Note that valid values for this
666 * option are specific to a given operating system.
667 *
668 * @param size The new receive buffer size.
669 *
670 * @exception SocketException If an error occurs or Socket is not connected
671 *
672 * @since 1.2
673 */
674 public void setReceiveBufferSize (int size) throws SocketException
675 {
676 if (impl == null)
677 throw new SocketException("Not connected");
678
679 if (size <= 0)
680 throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
681
682 impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
683 }
684
685 /**
686 * This method returns the value of the system level socket option
687 * SO_RCVBUF, which is used by the operating system to tune buffer
688 * sizes for data transfers.
689 *
690 * @return The receive buffer size.
691 *
692 * @exception SocketException If an error occurs or Socket is not connected
693 *
694 * @since 1.2
695 */
696 public int getReceiveBufferSize () throws SocketException
697 {
698 if (impl == null)
699 throw new SocketException("Not connected");
700
701 Object buf = impl.getOption(SocketOptions.SO_RCVBUF);
702
703 if (buf instanceof Integer)
704 return(((Integer)buf).intValue());
705 else
706 throw new SocketException("Internal Error: Unexpected type");
707 }
708
709 /**
710 * This method sets the value for the socket level socket option
711 * SO_KEEPALIVE.
712 *
713 * @param on True if SO_KEEPALIVE should be enabled
714 *
715 * @exception SocketException If an error occurs or Socket is not connected
716 *
717 * @since Java 1.3
718 */
719 public void setKeepAlive (boolean on) throws SocketException
720 {
721 if (impl == null)
722 throw new SocketException("Not connected");
723
724 impl.setOption(SocketOptions.SO_KEEPALIVE, new Boolean(on));
725 }
726
727 /**
728 * This method returns the value of the socket level socket option
729 * SO_KEEPALIVE.
730 *
731 * @return The setting
732 *
733 * @exception SocketException If an error occurs or Socket is not connected
734 *
735 * @since Java 1.3
736 */
737 public boolean getKeepAlive () throws SocketException
738 {
739 if (impl == null)
740 throw new SocketException("Not connected");
741
742 Object buf = impl.getOption(SocketOptions.SO_KEEPALIVE);
743
744 if (buf instanceof Boolean)
745 return(((Boolean)buf).booleanValue());
746 else
747 throw new SocketException("Internal Error: Unexpected type");
748 }
749
750 /**
751 * Closes the socket.
752 *
753 * @exception IOException If an error occurs
754 */
755 public synchronized void close () throws IOException
756 {
757 if (impl != null)
758 impl.close();
759 }
760
761 /**
762 * Converts this <code>Socket</code> to a <code>String</code>.
763 *
764 * @return The <code>String</code> representation of this <code>Socket</code>
765 */
766 public String toString ()
767 {
768 return("Socket " + impl);
769 }
770
771 // Class Methods
772
773 /**
774 * Sets the <code>SocketImplFactory</code>. This may be done only once per
775 * virtual machine. Subsequent attempts will generate a
776 * <code>SocketException</code>. Note that a <code>SecurityManager</code>
777 * check is made prior to setting the factory. If
778 * insufficient privileges exist to set the factory, then an
779 * <code>IOException</code> will be thrown.
780 *
781 * @exception SecurityException If the <code>SecurityManager</code> does
782 * not allow this operation.
783 * @exception SocketException If the SocketImplFactory is already defined
784 * @exception IOException If any other error occurs
785 */
786 public static synchronized void setSocketImplFactory (SocketImplFactory fac)
787 throws IOException
788 {
789 // See if already set
790 if (factory != null)
791 throw new SocketException("SocketImplFactory already defined");
792
793 // Check permissions
794 SecurityManager sm = System.getSecurityManager();
795 if (sm != null)
796 sm.checkSetFactory();
797
798 factory = fac;
799 }
800
801 /**
802 * Closes the input side of the socket stream.
803 *
804 * @exception IOException If an error occurs.
805 */
806 public void shutdownInput() throws IOException
807 {
808 if (impl != null)
809 impl.shutdownInput();
810 }
811
812 /**
813 * Closes the output side of the socket stream.
814 *
815 * @exception IOException If an error occurs.
816 */
817 public void shutdownOutput() throws IOException
818 {
819 if (impl != null)
820 impl.shutdownOutput();
821 }
822 }