Package org.java_websocket.drafts
Class Draft
- java.lang.Object
-
- org.java_websocket.drafts.Draft
-
- Direct Known Subclasses:
Draft_6455
public abstract class Draft extends java.lang.ObjectBase class for everything of a websocket specification which is not common such as the way the handshake is read or frames are transferred.
-
-
Field Summary
Fields Modifier and Type Field Description protected OpcodecontinuousFrameTypeprotected RoleroleIn some cases the handshake will be parsed different depending on whether
-
Constructor Summary
Constructors Constructor Description Draft()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract HandshakeStateacceptHandshakeAsClient(ClientHandshake request, ServerHandshake response)abstract HandshakeStateacceptHandshakeAsServer(ClientHandshake handshakedata)protected booleanbasicAccept(Handshakedata handshakedata)intcheckAlloc(int bytecount)java.util.List<Framedata>continuousFrame(Opcode op, java.nio.ByteBuffer buffer, boolean fin)abstract DraftcopyInstance()Drafts must only be by one websocket at all.abstract java.nio.ByteBuffercreateBinaryFrame(Framedata framedata)abstract java.util.List<Framedata>createFrames(java.lang.String text, boolean mask)abstract java.util.List<Framedata>createFrames(java.nio.ByteBuffer binary, boolean mask)java.util.List<java.nio.ByteBuffer>createHandshake(Handshakedata handshakedata)java.util.List<java.nio.ByteBuffer>createHandshake(Handshakedata handshakedata, boolean withcontent)java.util.List<java.nio.ByteBuffer>createHandshake(Handshakedata handshakedata, Role ownrole)Deprecated.use createHandshake without the rolejava.util.List<java.nio.ByteBuffer>createHandshake(Handshakedata handshakedata, Role ownrole, boolean withcontent)Deprecated.use createHandshake without the role since it does not have any effectabstract CloseHandshakeTypegetCloseHandshakeType()RolegetRole()abstract ClientHandshakeBuilderpostProcessHandshakeRequestAsClient(ClientHandshakeBuilder request)abstract HandshakeBuilderpostProcessHandshakeResponseAsServer(ClientHandshake request, ServerHandshakeBuilder response)abstract voidprocessFrame(WebSocketImpl webSocketImpl, Framedata frame)Handle the frame specific to the draftstatic java.nio.ByteBufferreadLine(java.nio.ByteBuffer buf)static java.lang.StringreadStringLine(java.nio.ByteBuffer buf)(package private) intreadVersion(Handshakedata handshakedata)abstract voidreset()voidsetParseMode(Role role)java.lang.StringtoString()abstract java.util.List<Framedata>translateFrame(java.nio.ByteBuffer buffer)HandshakedatatranslateHandshake(java.nio.ByteBuffer buf)static HandshakeBuildertranslateHandshakeHttp(java.nio.ByteBuffer buf, Role role)private static HandshakeBuildertranslateHandshakeHttpClient(java.lang.String[] firstLineTokens, java.lang.String line)Checking the handshake for the role as clientprivate static HandshakeBuildertranslateHandshakeHttpServer(java.lang.String[] firstLineTokens, java.lang.String line)Checking the handshake for the role as server
-
-
-
Method Detail
-
readLine
public static java.nio.ByteBuffer readLine(java.nio.ByteBuffer buf)
-
readStringLine
public static java.lang.String readStringLine(java.nio.ByteBuffer buf)
-
translateHandshakeHttp
public static HandshakeBuilder translateHandshakeHttp(java.nio.ByteBuffer buf, Role role) throws InvalidHandshakeException
- Throws:
InvalidHandshakeException
-
translateHandshakeHttpServer
private static HandshakeBuilder translateHandshakeHttpServer(java.lang.String[] firstLineTokens, java.lang.String line) throws InvalidHandshakeException
Checking the handshake for the role as server- Parameters:
firstLineTokens- the token of the first line split as as an string arrayline- the whole line- Returns:
- a handshake
- Throws:
InvalidHandshakeException
-
translateHandshakeHttpClient
private static HandshakeBuilder translateHandshakeHttpClient(java.lang.String[] firstLineTokens, java.lang.String line) throws InvalidHandshakeException
Checking the handshake for the role as client- Parameters:
firstLineTokens- the token of the first line split as as an string arrayline- the whole line- Returns:
- a handshake
- Throws:
InvalidHandshakeException
-
acceptHandshakeAsClient
public abstract HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHandshake response) throws InvalidHandshakeException
- Throws:
InvalidHandshakeException
-
acceptHandshakeAsServer
public abstract HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata) throws InvalidHandshakeException
- Throws:
InvalidHandshakeException
-
basicAccept
protected boolean basicAccept(Handshakedata handshakedata)
-
createBinaryFrame
public abstract java.nio.ByteBuffer createBinaryFrame(Framedata framedata)
-
createFrames
public abstract java.util.List<Framedata> createFrames(java.nio.ByteBuffer binary, boolean mask)
-
createFrames
public abstract java.util.List<Framedata> createFrames(java.lang.String text, boolean mask)
-
processFrame
public abstract void processFrame(WebSocketImpl webSocketImpl, Framedata frame) throws InvalidDataException
Handle the frame specific to the draft- Parameters:
webSocketImpl- the websocketimpl used for this draftframe- the frame which is supposed to be handled- Throws:
InvalidDataException- will be thrown on invalid data
-
continuousFrame
public java.util.List<Framedata> continuousFrame(Opcode op, java.nio.ByteBuffer buffer, boolean fin)
-
reset
public abstract void reset()
-
createHandshake
@Deprecated public java.util.List<java.nio.ByteBuffer> createHandshake(Handshakedata handshakedata, Role ownrole)
Deprecated.use createHandshake without the role
-
createHandshake
public java.util.List<java.nio.ByteBuffer> createHandshake(Handshakedata handshakedata)
-
createHandshake
@Deprecated public java.util.List<java.nio.ByteBuffer> createHandshake(Handshakedata handshakedata, Role ownrole, boolean withcontent)
Deprecated.use createHandshake without the role since it does not have any effect
-
createHandshake
public java.util.List<java.nio.ByteBuffer> createHandshake(Handshakedata handshakedata, boolean withcontent)
-
postProcessHandshakeRequestAsClient
public abstract ClientHandshakeBuilder postProcessHandshakeRequestAsClient(ClientHandshakeBuilder request) throws InvalidHandshakeException
- Throws:
InvalidHandshakeException
-
postProcessHandshakeResponseAsServer
public abstract HandshakeBuilder postProcessHandshakeResponseAsServer(ClientHandshake request, ServerHandshakeBuilder response) throws InvalidHandshakeException
- Throws:
InvalidHandshakeException
-
translateFrame
public abstract java.util.List<Framedata> translateFrame(java.nio.ByteBuffer buffer) throws InvalidDataException
- Throws:
InvalidDataException
-
getCloseHandshakeType
public abstract CloseHandshakeType getCloseHandshakeType()
-
copyInstance
public abstract Draft copyInstance()
Drafts must only be by one websocket at all. To prevent drafts to be used more than once the Websocket implementation should call this method in order to create a new usable version of a given draft instance.
The copy can be safely used in conjunction with a new websocket connection.- Returns:
- a copy of the draft
-
translateHandshake
public Handshakedata translateHandshake(java.nio.ByteBuffer buf) throws InvalidHandshakeException
- Throws:
InvalidHandshakeException
-
checkAlloc
public int checkAlloc(int bytecount) throws InvalidDataException- Throws:
InvalidDataException
-
readVersion
int readVersion(Handshakedata handshakedata)
-
setParseMode
public void setParseMode(Role role)
-
getRole
public Role getRole()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-