コード例 #1
0
ファイル: StreamUtil.java プロジェクト: ggd543/liferay-6.0.6
  public static void transfer(
      ReadableByteChannel readableByteChannel,
      WritableByteChannel writableByteChannel,
      boolean cleanUp)
      throws IOException {

    transfer(readableByteChannel, writableByteChannel, BUFFER_SIZE, cleanUp);
  }
コード例 #2
0
ファイル: StreamUtil.java プロジェクト: ggd543/liferay-6.0.6
  public static void transfer(
      ReadableByteChannel readableByteChannel,
      WritableByteChannel writableByteChannel,
      int bufferSize)
      throws IOException {

    transfer(readableByteChannel, writableByteChannel, bufferSize, true);
  }
コード例 #3
0
  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());
  }
コード例 #4
0
  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
ファイル: StreamUtil.java プロジェクト: ggd543/liferay-6.0.6
  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
ファイル: StreamUtil.java プロジェクト: ggd543/liferay-6.0.6
  public static void transfer(InputStream inputStream, OutputStream outputStream)
      throws IOException {

    transfer(inputStream, outputStream, BUFFER_SIZE, true);
  }
コード例 #9
0
ファイル: StreamUtil.java プロジェクト: ggd543/liferay-6.0.6
  public static void transfer(InputStream inputStream, OutputStream outputStream, int bufferSize)
      throws IOException {

    transfer(inputStream, outputStream, bufferSize, true);
  }
コード例 #10
0
ファイル: StreamUtil.java プロジェクト: ggd543/liferay-6.0.6
  public static void transfer(InputStream inputStream, OutputStream outputStream, boolean cleanUp)
      throws IOException {

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