List of usage examples for java.io DataInputStream readLine
@Deprecated public final String readLine() throws IOException
readLine
method of DataInput
. From source file:edu.udel.mxv.MxvMap.java
@Override protected void setup(Mapper<LongWritable, Text, IntWritable, DoubleWritable>.Context context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); String input_vector = conf.get("vector.path"); x_i = new double[conf.getInt("vector.n", 0)]; FileSystem fs = FileSystem.get(URI.create(input_vector), conf); FileStatus[] status = fs.listStatus(new Path(input_vector)); for (int i = 0; i < status.length; ++i) { Path file = status[i].getPath(); System.out.println("status: " + i + " " + file.toString()); DataInputStream dis = new DataInputStream(fs.open(file)); String line = null;//from w w w. j a va 2s. c o m int count = 0; while ((line = dis.readLine()) != null) { String[] split_line = line.split(","); if (split_line.length == 2) { int pos = Integer.parseInt(split_line[0]); double val = Double.parseDouble(split_line[1]); x_i[pos++] = val; count++; } else LOG.error("Parse error in line: " + line); } LOG.info("Number of elements read for vector = " + count); } }
From source file:org.apache.hms.agent.dispatcher.ShellRunner.java
public Response run(ScriptCommand cmd) { Response r = new Response(); StringBuilder stdout = new StringBuilder(); StringBuilder errorBuffer = new StringBuilder(); Process proc;//from ww w. j av a2 s .c o m try { String[] parameters = cmd.getParms(); int size = 0; if (parameters != null) { size = parameters.length; } String[] cmdArray = new String[size + 1]; cmdArray[0] = cmd.getScript(); for (int i = 0; i < size; i++) { cmdArray[i + 1] = parameters[i]; } proc = Runtime.getRuntime().exec(cmdArray); DataInputStream in = new DataInputStream(proc.getInputStream()); DataInputStream err = new DataInputStream(proc.getErrorStream()); String str; while ((str = in.readLine()) != null) { stdout.append(str); stdout.append("\n"); } while ((str = err.readLine()) != null) { errorBuffer.append(str); errorBuffer.append("\n"); } int exitCode = proc.waitFor(); r.setCode(exitCode); r.setError(errorBuffer.toString()); r.setOutput(stdout.toString()); } catch (Exception e) { r.setCode(1); r.setError(ExceptionUtil.getStackTrace(e)); log.error(ExceptionUtil.getStackTrace(e)); } log.info(cmd); log.info(r); return r; }
From source file:org.apache.hadoop.io.crypto.tool.CryptoApiTool.java
private void writeStreamLine(DataInputStream input, CompressionOutputStream output) throws IOException { String line;/*from www . ja v a2 s . c om*/ while ((line = input.readLine()) != null) { output.write(line.getBytes("UTF-8")); output.write("\n".getBytes("UTF-8")); } output.flush(); }
From source file:com.librelio.products.ui.ProductsBillingActivity.java
private static String getTempURL(HttpResponse response) { String tempURL = null;//from www. j a va 2 s . c o m Log.d(TAG, "status line: " + response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); DataInputStream bodyStream = null; if (entity != null) { try { bodyStream = new DataInputStream(entity.getContent()); StringBuilder content = new StringBuilder(); if (null != bodyStream) { String line = null; while ((line = bodyStream.readLine()) != null) { content.append(line).append("\n"); } } Log.d(TAG, "body: " + content.toString()); } catch (Exception e) { Log.e(TAG, "get content failed", e); } finally { try { bodyStream.close(); } catch (Exception e) { } } } if (null != response.getAllHeaders()) { for (Header h : response.getAllHeaders()) { if (h.getName().equalsIgnoreCase("location")) { tempURL = h.getValue(); } Log.d(TAG, "header: " + h.getName() + " => " + h.getValue()); } } return tempURL; }
From source file:org.jbpm.designer.server.EngineProxy.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) { try {/* w w w . j av a 2 s .c o m*/ String engineURL = req.getParameter("url"); String user = req.getHeader("Authorization"); if (user != null) { java.util.StringTokenizer st = new java.util.StringTokenizer(user); if (st.hasMoreTokens()) { if (st.nextToken().equalsIgnoreCase("Basic")) { String userPass = new String(Base64.decodeBase64(st.nextToken())); user = userPass.split(":")[0]; } } } if (user == null) { resp.setHeader("WWW-Authenticate", "BASIC realm=\"Please type in your username here\""); resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } URL url_engine = new URL(engineURL); HttpURLConnection connection_engine = (HttpURLConnection) url_engine.openConnection(); connection_engine.setRequestMethod("GET"); String encoding = Base64.encodeBase64String((user + ":").getBytes()); connection_engine.setRequestProperty("Authorization", "Basic " + encoding); connection_engine.setDoInput(true); connection_engine.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection_engine.setRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); connection_engine.connect(); if (connection_engine.getResponseCode() == 200) { DataInputStream in = new DataInputStream(connection_engine.getInputStream()); String str; String xmlDoc = ""; while ((str = in.readLine()) != null) { xmlDoc += str + " "; } /* xmlDoc = xmlDoc.replaceAll("href=\"/", "href=\"/oryx/engineproxy?url="+url_engine.getProtocol()+"://"+url_engine.getHost()+":"+url_engine.getPort()+"/"); xmlDoc = xmlDoc.replaceAll("src=\"/", "src=\"/oryx/engineproxy?url="+url_engine.getProtocol()+"://"+url_engine.getHost()+":"+url_engine.getPort()+"/"); xmlDoc = xmlDoc.replaceAll("action=\"/", "action=\"/oryx/engineproxy?url="+url_engine.getProtocol()+"://"+url_engine.getHost()+":"+url_engine.getPort()+"/"); */ PrintWriter out = resp.getWriter(); out.print(xmlDoc); } } catch (Exception e1) { e1.printStackTrace(); } }
From source file:org.wyona.yanel.impl.resources.updatefinder.utils.TomcatContextHandler.java
/** * @param String context/* w w w .j a v a2 s. c o m*/ * @return String webapp or null if webapp not exists or null if context points to webapp which does not exist */ public String getWebappOfContext(String context) throws FileNotFoundException, IOException { File file = new File(contextConfPath + context + ".xml"); if (!file.exists()) { return null; } String line = ""; String webapp = ""; FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); while (dis.available() != 0) { line = line + dis.readLine(); } fis.close(); bis.close(); dis.close(); if (line.indexOf("yanel-webapps") <= 0) { return ""; } line = line.replaceAll("[ ]+", " "); line = line.replaceAll("\"/>", ""); webapp = line.split("/")[line.split("/").length - 1]; if (!new File(webappsDirectoryPath + webapp).exists()) { return null; } return webapp; }
From source file:org.wyona.yanel.impl.resources.updatefinder.utils.TomcatContextHandler.java
/** * @param ArrayList contexts/* w w w. j a v a 2 s .com*/ * @return ArrayList with all contexts which pionts to the webapp or null if webapp not exists or no conext points to this webapp (will never return ROOT as context) */ public List<String> getContextsOfWebapp(String webapp) throws FileNotFoundException, IOException { List<String> contexts = new ArrayList<String>(); for (int i = 0; i < this.contextConfDirectory.listFiles().length; i++) { String line = ""; FileInputStream fis = new FileInputStream(contextConfDirectory.listFiles()[i]); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); while (dis.available() != 0) { line = line + dis.readLine(); } fis.close(); bis.close(); dis.close(); if (line.indexOf(webapp) > 0) { contexts.add(contextConfDirectory.listFiles()[i].getName().replaceAll(".xml", "")); } } if (contexts.size() < 1) { return null; } return contexts; }
From source file:com.karpenstein.signalmon.NetConnHandler.java
@Override public void run() { server.addListener(this); String line;/*from www . j av a2 s. com*/ try { Log.d("NetConnHandler", "about to create input and output streams"); // Get input from the client DataInputStream in = new DataInputStream(sock.getInputStream()); PrintStream out = new PrintStream(sock.getOutputStream()); Log.d("NetConnHandler", "about to start looping"); while ((line = in.readLine()) != null && line.equals("G")) { if (stateChanged) { stateChanged = false; out.println(state.toString()); } else out.println(nullObj); } sock.close(); } catch (IOException ioe) { Log.e("SignalMonitor.NetConnHandler", "IOException on socket r/w: " + ioe, ioe); } }
From source file:com.sabre.hack.travelachievementgame.DSCommHandler.java
@SuppressWarnings("deprecation") public String sendRequest(String payLoad, String authToken) { URLConnection conn = null;/*from ww w . j a va 2 s.co m*/ String strRet = null; try { URL urlConn = new URL(payLoad); conn = null; conn = urlConn.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestProperty("Authorization", "Bearer " + authToken); conn.setRequestProperty("Accept", "application/json"); DataInputStream dataIn = new DataInputStream(conn.getInputStream()); String strChunk = ""; StringBuilder sb = new StringBuilder(""); while (null != ((strChunk = dataIn.readLine()))) sb.append(strChunk); strRet = sb.toString(); } catch (MalformedURLException e) { // TODO Auto-generated catch block System.out.println("MalformedURLException in DSCommHandler"); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("IOException in DSCommHandler: " + conn.getHeaderField(0)); // e.printStackTrace(); } return strRet; }
From source file:org.alfresco.webservice.util.ContentUtils.java
/** * Streams content into the repository. Once done a content details string is returned and this can be used to update * a content property in a CML statement. * /*from w w w . j a v a 2 s . co m*/ * @param file the file to stream into the repository * @param host the host name of the destination repository * @param port the port name of the destination repository * @param webAppName the name of the target web application (default 'alfresco') * @param mimetype the mimetype of the file, ignored if null * @param encoding the encoding of the file, ignored if null * @return the content data that can be used to set the content property in a CML statement */ @SuppressWarnings("deprecation") public static String putContent(File file, String host, int port, String webAppName, String mimetype, String encoding) { String result = null; try { String url = "/" + webAppName + "/upload/" + URLEncoder.encode(file.getName(), "UTF-8") + "?ticket=" + AuthenticationUtils.getTicket(); if (mimetype != null) { url = url + "&mimetype=" + mimetype; } if (encoding != null) { url += "&encoding=" + encoding; } String request = "PUT " + url + " HTTP/1.1\n" + "Cookie: JSESSIONID=" + AuthenticationUtils.getAuthenticationDetails().getSessionId() + ";\n" + "Content-Length: " + file.length() + "\n" + "Host: " + host + ":" + port + "\n" + "Connection: Keep-Alive\n" + "\n"; // Open sockets and streams Socket socket = new Socket(host, port); DataOutputStream os = new DataOutputStream(socket.getOutputStream()); DataInputStream is = new DataInputStream(socket.getInputStream()); try { if (socket != null && os != null && is != null) { // Write the request header os.writeBytes(request); // Stream the content onto the server InputStream fileInputStream = new FileInputStream(file); int byteCount = 0; byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = fileInputStream.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); byteCount += bytesRead; } os.flush(); fileInputStream.close(); // Read the response and deal with any errors that might occur boolean firstLine = true; String responseLine; while ((responseLine = is.readLine()) != null) { if (firstLine == true) { if (responseLine.contains("200") == true) { firstLine = false; } else if (responseLine.contains("401") == true) { throw new RuntimeException( "Content could not be uploaded because invalid credentials have been supplied."); } else if (responseLine.contains("403") == true) { throw new RuntimeException( "Content could not be uploaded because user does not have sufficient privileges."); } else { throw new RuntimeException( "Error returned from upload servlet (" + responseLine + ")"); } } else if (responseLine.contains("contentUrl") == true) { result = responseLine; break; } } } } finally { try { // Close the streams and socket if (os != null) { os.close(); } if (is != null) { is.close(); } if (socket != null) { socket.close(); } } catch (Exception e) { throw new RuntimeException("Error closing sockets and streams", e); } } } catch (Exception e) { throw new RuntimeException("Error writing content to repository server", e); } return result; }