예제 #1
0
  public static void transfer(
      ReadableByteChannel readableByteChannel,
      WritableByteChannel writableByteChannel,
      boolean cleanUp)
      throws IOException {

    transfer(readableByteChannel, writableByteChannel, BUFFER_SIZE, cleanUp);
  }
예제 #2
0
  public static void transfer(
      ReadableByteChannel readableByteChannel,
      WritableByteChannel writableByteChannel,
      int bufferSize)
      throws IOException {

    transfer(readableByteChannel, writableByteChannel, bufferSize, true);
  }
  public static void write(HttpServletResponse response, InputStream is, long contentLength)
      throws IOException {

    if (response.isCommitted()) {
      return;
    }

    if (contentLength > 0) {
      response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength));
    }

    response.flushBuffer();

    StreamUtil.transfer(is, response.getOutputStream());
  }
  protected void copyJar(ServletContext servletContext, String dir, String jarName)
      throws Exception {

    String servletContextName = servletContext.getServletContextName();

    String jarFullName = "/WEB-INF/" + jarName + "/" + jarName + ".jar";

    InputStream is = servletContext.getResourceAsStream(jarFullName);

    if (is == null) {
      throw new HotDeployException(jarFullName + " does not exist");
    }

    String newJarFullName = dir + "ext-" + servletContextName + jarName.substring(3) + ".jar";

    StreamUtil.transfer(is, new FileOutputStream(new File(newJarFullName)));
  }
예제 #5
0
  @Override
  public void executeRead(
      HttpServletRequest request, JSONObject responseJSONObject, Queue<String> arguments)
      throws Exception {

    File logFile = getLogFile();

    if ((logFile == null) || !logFile.exists()) {
      return;
    }

    InputStream inputStream = new FileInputStream(logFile);

    int offset = GetterUtil.getInteger(arguments.poll());

    inputStream.skip(offset);

    OutputStream outputStream = new ByteArrayOutputStream();

    StreamUtil.transfer(inputStream, outputStream);

    responseJSONObject.put(JSONKeys.OUTPUT, outputStream.toString());
  }
예제 #6
0
  private String _getResourcePath(String resource) throws IOException {
    InputStream is = getClass().getResourceAsStream("dependencies/" + resource);

    if (is == null) {
      return null;
    }

    String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);

    File file = new File(tmpDir + "/liferay/com/liferay/portal/deploy/dependencies/" + resource);

    // if (!file.exists() || resource.startsWith("ext-")) {
    File parentFile = file.getParentFile();

    if (parentFile != null) {
      parentFile.mkdirs();
    }

    StreamUtil.transfer(is, new FileOutputStream(file));
    // }

    return FileUtil.getAbsolutePath(file);
  }
예제 #7
0
  public static void transfer(
      InputStream inputStream, OutputStream outputStream, int bufferSize, boolean cleanUp)
      throws IOException {

    if (inputStream == null) {
      throw new IllegalArgumentException("Input stream cannot be null");
    }

    if (outputStream == null) {
      throw new IllegalArgumentException("Output stream cannot be null");
    }

    if (bufferSize <= 0) {
      bufferSize = BUFFER_SIZE;
    }

    if (USE_NIO) {
      ReadableByteChannel readableByteChannel = Channels.newChannel(inputStream);
      WritableByteChannel writableByteChannel = Channels.newChannel(outputStream);

      transfer(readableByteChannel, writableByteChannel, bufferSize, cleanUp);
    } else {
      try {
        byte[] bytes = new byte[bufferSize];

        int value = -1;

        while ((value = inputStream.read(bytes)) != -1) {
          outputStream.write(bytes, 0, value);
        }
      } finally {
        if (cleanUp) {
          cleanUp(inputStream, outputStream);
        }
      }
    }
  }
예제 #8
0
  public static void transfer(InputStream inputStream, OutputStream outputStream)
      throws IOException {

    transfer(inputStream, outputStream, BUFFER_SIZE, true);
  }
예제 #9
0
  public static void transfer(InputStream inputStream, OutputStream outputStream, int bufferSize)
      throws IOException {

    transfer(inputStream, outputStream, bufferSize, true);
  }
예제 #10
0
  public static void transfer(InputStream inputStream, OutputStream outputStream, boolean cleanUp)
      throws IOException {

    transfer(inputStream, outputStream, BUFFER_SIZE, cleanUp);
  }