Package sunlabs.brazil.util.http

Examples of sunlabs.brazil.util.http.HttpInputStream


    sh[2] = command;
    process = Runtime.getRuntime().exec(sh);
      } else {
    process = Runtime.getRuntime().exec(command);
      }
      HttpInputStream in = new HttpInputStream(process.getInputStream());
      HttpInputStream err = new HttpInputStream(process.getErrorStream());

      // If we have stdin data in a property, send it to the process

      String stdin = hr.get("stdin");
      if (stdin != null) {
    OutputStream out = process.getOutputStream();
    out.write(stdin.getBytes());
    out.close();
      }

      // Read the streams into the proper properties

      ByteArrayOutputStream buff = new ByteArrayOutputStream();
      in.copyTo(buff);
      in.close();
      String enc = null;
      if (encoding != null) {
         enc = buff.toString(encoding);
      } else {
         enc = buff.toString();
      }
      hr.request.props.put(prepend + "stdout", enc);
      buff.reset();

      err.copyTo(buff);
      err.close();
      if (encoding != null) {
         enc = buff.toString(encoding);
      } else {
         enc = buff.toString();
      }
View Full Code Here


      OutputStream out = process.getOutputStream();
      out.write(content);
      out.close();

      HttpInputStream in = new HttpInputStream(process.getInputStream());
      HttpInputStream err = new HttpInputStream(process.getErrorStream());

      ByteArrayOutputStream inB = new ByteArrayOutputStream();

      in.copyTo(inB);
      if (inB.size() > 0) {
          content=inB.toByteArray();
          String newType = request.props.getProperty(prefix + "newType");
    if (newType != null) {
        newType = Format.subst(request.props, newType);
        request.log(Server.LOG_DIAGNOSTIC, prefix +
          "Changing content type to: " + newType);
        headers.put("content-type", newType);
    }
      } else {
    request.log(Server.LOG_DIAGNOSTIC, prefix +
      "No content from filter");
      }
      in.close();
      inB.close();

      ByteArrayOutputStream errB = new ByteArrayOutputStream();
      err.copyTo(errB);
      if (errB.size() > 0) {
    request.log(Server.LOG_DIAGNOSTIC, prefix +
       "Error result: " + errB);
    request.props.put(prefix + "error", errB.toString());
      }
      err.close();
      errB.close();

      process.waitFor();
  } catch (Exception e) {
      request.log(Server.LOG_DIAGNOSTIC, prefix +
View Full Code Here

    public Regexp
    loadUrls(Properties props, String prefix, String file)
    {
  StringBuffer sb = new StringBuffer();
  try {
      HttpInputStream in = new HttpInputStream(
        ResourceHandler.getResourceStream(props, prefix, file));

      String line;
      while ((line = in.readLine()) != null) {
    line = line.trim();
    if ((line.length() == 0) || (line.charAt(0) == '#')) {
        continue;
    }
    sb.append(line).append('|');
View Full Code Here

      PrintStream out = new PrintStream(sock.getOutputStream());
      out.println(host + " " + port);
      out.flush();
      out = null;

      HttpInputStream in = new HttpInputStream(sock.getInputStream());
      while (true) {
    String line = in.readLine();
/*System.out.println(line);*/
    if ((line == null) || line.endsWith("refused")) {
        throw new ConnectException(host + ":" + port);
    }
    if (line.startsWith("connected to")) {
View Full Code Here

    {
  this.server = server;
  this.sock = sock;

  try {
      in = new HttpInputStream(
        new BufferedInputStream(sock.getInputStream()));
      out = new HttpOutputStream(
        new BufferedOutputStream(sock.getOutputStream()));
  } catch (IOException e) {
      /*
 
View Full Code Here

     */
    public void
    sendResponse(InputStream in, int length, String type, int code)
  throws IOException
    {
  HttpInputStream hin = new HttpInputStream(in);

  byte[] buf = new byte[server.bufsize];
     
  if (length >= 0) {
      sendHeaders(code, type, length);
      if (!method.equals("HEAD")) {
         if (hin.copyTo(out, length, buf) != length) {
       keepAlive = false;
         }
      }
  } else if (version <= 10) {
      keepAlive = false;
      sendHeaders(code, type, -1);
      if (!method.equals("HEAD")) {
         hin.copyTo(out, -1, buf);
      }
  } else {
      if (method.equals("HEAD")) {
          sendHeaders(code, type, -1);
    return;
      }

      addHeader("Transfer-Encoding", "chunked");
      sendHeaders(code, type, -1);

      while (true) {
    int count = hin.read(buf);
    if (count < 0) {
        out.writeBytes("0\r\n\r\n");
        break;
    }
    out.writeBytes(Integer.toHexString(count) + "\r\n");
View Full Code Here

  }

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  String result = null;
  try {
      HttpInputStream hin = new HttpInputStream(
        ResourceHandler.getResourceStream(
      hr.request.props, hr.prefix, src));
      hin.copyTo(baos);
      hin.close();
  } catch (IOException e) {
      debug(hr, "Bad import file: " + e);
      return;
  }
  if (enc != null) {
View Full Code Here

  try {
      Socket s = new Socket(host, port);
      out = new Request.HttpOutputStream(
      s.getOutputStream());
      SocketReader reader = new SocketReader(queueName,
        new HttpInputStream( s.getInputStream()));
      reader.start();
      String login = "Action: login\r\nUserName: " + user + "\r\n" +
    "Secret: " + pass + "\r\n\r\n";
      out.writeBytes(login);
      out.flush();
View Full Code Here

      if (!file.isDirectory()) {
    file = new File(file.getParent());
      }
      file = new File(file, name);
  }
  HttpInputStream hin = new HttpInputStream(in);
  try {
      FileOutputStream out = new FileOutputStream(file);
      hin.copyTo(out);
      log(hr, Server.LOG_DIAGNOSTIC, "wrote file: " + file);
  } catch (IOException e) {
      log(hr, Server.LOG_LOG, "Can't write file: " + e.getMessage());
  }
    }
View Full Code Here

    getResourceString(Properties props, String prefix, String file)
  throws IOException
    {
  InputStream in = getResourceStream(props, prefix, file);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  new HttpInputStream(in).copyTo(out);
        in.close();
  return out.toString();
    }
View Full Code Here

TOP

Related Classes of sunlabs.brazil.util.http.HttpInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.