Top Description Fields Constructors Methods
org.codehaus.groovy.runtime

public Class SocketGroovyMethods

extends DefaultGroovyMethodsSupport
Class Inheritance
Imports
groovy.lang.Closure, groovy.transform.stc.ClosureParams, .SimpleType, java.io.IOException, .InputStream, .ObjectInputStream, .ObjectOutputStream, .OutputStream, .Writer, java.net.ServerSocket, .Socket, java.util.logging.Logger

This class defines new groovy methods for Sockets which enhance JDK classes inside the Groovy environment.

Note

While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Socket

Returns:

a Socket
accept
(ServerSocket
a ServerSocket
serverSocket
,
final Closure<V>
a Closure
closure
)

Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread.

public static Socket

Returns:

a Socket
accept
(ServerSocket
a ServerSocket
serverSocket
,
final boolean
This flag should be true, if the closure should be invoked in a new thread, else false.
runInANewThread
,
final Closure<V>
a Closure
closure
)

Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread or the calling thread, as needed.

private static void
public static Writer

Returns:

a Writer
leftShift
(Socket
a Socket
self
,
Object
a value to append
value
)

Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket

public static OutputStream

Returns:

an OutputStream
leftShift
(Socket
a Socket
self
,
byte[]
a value to append
value
)

Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket

public static <T> T

Returns:

the value returned by the closure
withObjectStreams
(Socket
this Socket
socket
,
Closure<T>
a Closure
closure
)

Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure.

public static <T> T

Returns:

the value returned by the closure
withStreams
(Socket
a Socket
socket
,
Closure<T>
a Closure
closure
)

Passes the Socket's InputStream and OutputStream to the closure.

Inherited from org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport:
cloneSimilarCollectioncloneSimilarMapcloseQuietlycloseWithWarningcreateSimilarArraycreateSimilarCollectioncreateSimilarCollectioncreateSimilarCollectioncreateSimilarListcreateSimilarMapcreateSimilarOrDefaultCollectioncreateSimilarQueuecreateSimilarSetnormaliseIndexsameTypesubListBorderssubListBorderstryClosewriteUTF16BomIfRequiredwriteUTF16BomIfRequiredwriteUTF16BomIfRequiredwriteUTF16BomIfRequired

Field Detail

LOGback to summary
private static final Logger LOG

Hides org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport.LOG.

Constructor Detail

SocketGroovyMethodsback to summary
public SocketGroovyMethods()

Method Detail

acceptback to summary
public static Socket accept(ServerSocket serverSocket, final Closure<V> closure) throws IOException

Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread.

Parameters
serverSocket:ServerSocket

a ServerSocket

closure:Closure<V>

a Closure

Returns:Socket

a Socket

Exceptions
IOException:
if an IOException occurs.
Since
1.0
See Also
java.net.ServerSocket#accept()
acceptback to summary
public static Socket accept(ServerSocket serverSocket, final boolean runInANewThread, final Closure<V> closure) throws IOException

Accepts a connection and passes the resulting Socket to the closure which runs in a new Thread or the calling thread, as needed.

Parameters
serverSocket:ServerSocket

a ServerSocket

runInANewThread:boolean

This flag should be true, if the closure should be invoked in a new thread, else false.

closure:Closure<V>

a Closure

Returns:Socket

a Socket

Exceptions
IOException:
if an IOException occurs.
Since
1.7.6
See Also
java.net.ServerSocket#accept()
invokeClosureWithSocketback to summary
private static void invokeClosureWithSocket(Socket socket, Closure<V> closure)
leftShiftback to summary
public static Writer leftShift(Socket self, Object value) throws IOException

Overloads the left shift operator to provide an append mechanism to add things to the output stream of a socket

Parameters
self:Socket

a Socket

value:Object

a value to append

Returns:Writer

a Writer

Exceptions
IOException:
if an IOException occurs.
Since
1.0
leftShiftback to summary
public static OutputStream leftShift(Socket self, byte[] value) throws IOException

Overloads the left shift operator to provide an append mechanism to add bytes to the output stream of a socket

Parameters
self:Socket

a Socket

value:byte[]

a value to append

Returns:OutputStream

an OutputStream

Exceptions
IOException:
if an IOException occurs.
Since
1.0
withObjectStreamsback to summary
public static <T> T withObjectStreams(Socket socket, Closure<T> closure) throws IOException

Creates an InputObjectStream and an OutputObjectStream from a Socket, and passes them to the closure. The streams will be closed after the closure returns, even if an exception is thrown.

Parameters
socket:Socket

this Socket

closure:Closure<T>

a Closure

Returns:T

the value returned by the closure

Exceptions
IOException:
if an IOException occurs.
Since
1.5.0
withStreamsback to summary
public static <T> T withStreams(Socket socket, Closure<T> closure) throws IOException

Passes the Socket's InputStream and OutputStream to the closure. The streams will be closed after the closure returns, even if an exception is thrown.

Parameters
socket:Socket

a Socket

closure:Closure<T>

a Closure

Returns:T

the value returned by the closure

Exceptions
IOException:
if an IOException occurs.
Since
1.5.2