List of utility methods to do Socket Read
String | dump(final Socket socket) Dumps the state of a socket if (socket == null) return "Socket [null]"; final StringBuilder b = new StringBuilder("Socket ["); b.append("\n\tConnected:").append(socket.isConnected()); final SocketAddress lsa = socket.getLocalSocketAddress(); final SocketAddress sa = socket.getRemoteSocketAddress(); if (sa != null && (sa instanceof InetSocketAddress)) { final InetSocketAddress isa = (InetSocketAddress) sa; ... |
BufferedReader | getBufferedReader(Socket s) get Buffered Reader return new BufferedReader(new InputStreamReader(s.getInputStream())); |
BufferedReader | getBufferedReaderFromInputStream(Socket socket) get Buffered Reader From Input Stream return new BufferedReader(new InputStreamReader(socket.getInputStream())); |
InputStream | getInputStream(Socket socket) get Input Stream try { return socket.getInputStream(); } catch (IOException e) { e.printStackTrace(); return null; |
InputStream | getInputStreamFromSocket(final Socket socket) Returns a InputStream from the specified socket return socket.getInputStream();
|
PrintWriter | getPrintWriter(Socket s) get Print Writer return new PrintWriter(s.getOutputStream()); |
PrintWriter | getPrintWriterFromOutputStream(Socket socket) get Print Writer From Output Stream return new PrintWriter(socket.getOutputStream()); |
String | getResponse(Socket socket) get Response BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String response = in.readLine(); return response; |
byte[] | readBytesIntoSocket(Socket socket) read Bytes Into Socket DataInputStream dis = new DataInputStream(socket.getInputStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int count = 0; byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; while (dis.available() == 0) { Thread.sleep(1); while ((count = dis.read(buffer)) > 0) { ... |
int | readData(Socket connId, byte[] dataRead, int nchar) Reads nchar from a given sockets, blocks on read untill nchar are read of conenction has error bRead returns the bytes read InputStream input; input = connId.getInputStream(); int nread = 0; int startTime = (int) (new Date().getTime()); do { if (input.available() != 0) { nread += input.read(dataRead, nread, nchar - nread); startTime = (int) (new Date().getTime()); ... |