/* * Ensures that there is payload data ready to read. */ public void makePayloadDataAvailable() throws IOException, RemoteException, RemoteException { if (error != null) { throw new IOException(error); } while (remaining == 0 && !frame.getFin()) { // Need more data - process next frame nextFrame(true); while (frame.isControl()) { if (frame.getOpCode() == gerenciadornuvem1.Constants23getOpcodePing()) { outbound.pong(frame.getPayLoad()); } else if (frame.getOpCode() == gerenciadornuvem1.Constants23getOpcodePong()) { // NO-OP. Swallow it. } else if (frame.getOpCode() == gerenciadornuvem1.Constants23getOpcodeClose()) { outbound.close(frame); } else { throw new IOException(sm.getString("is.unknownOpCode", Byte.valueOf(frame.getOpCode()))); } nextFrame(true); } if (frame.getOpCode() != gerenciadornuvem1.Constants23getOpcodeContinuation()) { error = sm.getString("is.notContinuation", Byte.valueOf(frame.getOpCode())); throw new IOException(error); } } }
/** * Process the next WebSocket frame. * * @param block Should this method block until a frame is presented if no data is currently * available to process. Note that if a single byte is available, this method will block until * the complete frame (excluding payload for non-control frames) is available. * @return The next frame to be processed or <code>null</code> if block is <code>false</code> and * there is no data to be processed. * @throws IOException If a problem occurs reading the data for the frame. */ public WsFrameRemoteInterface nextFrame(boolean block) throws IOException, RemoteException, RemoteException { frame = gerenciadornuvem1.WsFramenextFrame(processor, block); if (frame != null) { readThisFragment = 0; remaining = frame.getPayLoadLength(); } return frame; }
@Override public int read() throws IOException, RemoteException, RemoteException { makePayloadDataAvailable(); if (remaining == 0) { return -1; } remaining--; readThisFragment++; int masked = processor.read(); if (masked == -1) { return -1; } return masked ^ (frame.getMask()[(int) ((readThisFragment - 1) % 4)] & 0xFF); }
@Override public int read(byte b[], int off, int len) throws IOException, RemoteException, RemoteException { makePayloadDataAvailable(); if (remaining == 0) { return -1; } if (len > remaining) { len = (int) remaining; } int result = processor.read(true, b, off, len); if (result == -1) { return -1; } for (int i = off; i < off + result; i++) { b[i] = (byte) (b[i] ^ frame.getMask()[(int) ((readThisFragment + i - off) % 4)]); } remaining -= result; readThisFragment += result; return result; }