protected void readAlignments(BufferedReader stdInput, InputStream errorStream) throws IOException { String outLine; SAMAlignmentReader alignmentReader = new SAMAlignmentReader(); while ((outLine = stdInput.readLine()) != null) { if (logger.isDebugEnabled()) { logger.debug("LINE: " + outLine); } if (outLine.startsWith("@")) { logger.debug("SAM HEADER LINE: " + outLine); continue; } String readPairId = outLine.substring(0, outLine.indexOf('\t')); if (readPairId.endsWith("/1") || readPairId.endsWith("/2")) { readPairId = readPairId.substring(0, readPairId.length() - 2); } AlignmentRecord alignment = alignmentReader.parseRecord(outLine); if (!alignment.isMapped()) { continue; } getOutput().collect(new Text(readPairId), new Text(outLine)); } String errLine; BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream)); while ((errLine = errorReader.readLine()) != null) { logger.error("ERROR: " + errLine); } }
public final void writeASCII(String s) throws IOException { if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException(); OutputStream os = getOutputStream(); synchronized (os) { if (Defines.DEBUG && CAT.isDebugEnabled()) CAT.debug("C: " + s); os.write(s.getBytes("ASCII")); os.write((byte) 13); os.write((byte) 10); os.flush(); } }
public final String readCommand(byte[] b) throws IOException, InterruptedException, MessagingNetworkException { InputStream is = getInputStream(); synchronized (is) { long abortTime = System.currentTimeMillis() + 1000 * MSNMessagingNetwork.REQPARAM_SOCKET_TIMEOUT_SECONDS; int ofs = 0; boolean d = false; for (; ; ) { if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException(); int by = is.read(); if (by == -1) throw new IOException("unexpected EOF"); if (by == 10 && d) break; d = (by == 13); if (ofs < b.length) { b[ofs++] = (byte) by; } if (System.currentTimeMillis() > abortTime) throw new IOException("connection timed out"); /* if (len >= buffer.length) { ... return ...; } int pos = findCRLF(); if (pos != -1) break; fill(is, abortTime); */ } if (b[ofs - 1] == 13) --ofs; String line = new String(b, 0, ofs, "ASCII"); if (StringUtil.startsWith(line, "MSG")) { StringTokenizer st = new StringTokenizer(line); String len_s = null; while (st.hasMoreTokens()) { len_s = st.nextToken(); } if (len_s == null) throw new AssertException("len_s is null"); int len; try { len = Integer.parseInt(len_s); } catch (NumberFormatException ex) { ServerConnection.throwProtocolViolated("MSG length must be int"); len = 0; } String msg = readMSG(len); line = line + "\r\n" + msg; } if (Defines.DEBUG && CAT.isDebugEnabled()) CAT.debug("S: " + line); return line; } }
/** * UTF byte count is appended to the asciiPrefix, then UTF bytes are appended to the result; the * final result is sent. */ public final void writeMSG(String asciiPrefix, String msgBody) throws IOException { if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException(); OutputStream os = getOutputStream(); synchronized (os) { byte[] utfBytes = msgBody.getBytes("UTF-8"); asciiPrefix = asciiPrefix + ' ' + utfBytes.length; if (Defines.DEBUG && CAT.isDebugEnabled()) CAT.debug("C: " + asciiPrefix + "\r\n" + msgBody); os.write(asciiPrefix.getBytes("ASCII")); os.write((byte) 13); os.write((byte) 10); os.write(utfBytes); os.flush(); } }