• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StreamUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.log4j.lf5.util.StreamUtils的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils类的具体用法?Java StreamUtils怎么用?Java StreamUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StreamUtils类属于org.apache.log4j.lf5.util包,在下文中一共展示了StreamUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadKeys

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
private void loadKeys() throws Exception {
	
	InputStream in = new FileInputStream(prvFile);
	byte[] prvBytes = StreamUtils.getBytes(in);
	IOUtils.closeQuietly(in);
	
	in = new FileInputStream(pubFile);
	byte[] pubBytes = StreamUtils.getBytes(in);
	IOUtils.closeQuietly(in);

	PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(prvBytes);
	X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubBytes);
	KeyFactory kf = KeyFactory.getInstance("RSA");
       
       privateKey = kf.generatePrivate(privateKeySpec);
       publicKey = kf.generatePublic(publicKeySpec);
       
}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:19,代码来源:RsaEncryptionProvider.java


示例2: doPost

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
{
  log.debug("Start doPost");
  try {
    // Inputstream
    final InputStream is = request.getInputStream();
    final byte[] buffer = StreamUtils.getBytes(is);
    String filename;
    String croppedname;
    if (request.getParameter("croppedname") != null) {
      croppedname = request.getParameter("croppedname");
    } else {
      croppedname = "cropped";
    }
    if ((request.getParameter("filename") != null) && (request.getParameter("filetype") != null)) {
      filename = croppedname + request.getParameter("filename") + "." + request.getParameter("filetype");
    } else {
      filename = "image.png";
    }
    log.info("Filename: " + filename);
    ResponseUtils.streamToOut(filename, buffer, response, request.getSession().getServletContext(), true);
  } catch (Exception ex) {
    log.warn("Failure reading the request");
    log.warn(ex.getMessage(), ex);
  }
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:27,代码来源:UpAndDownloadImageFileAsByteArray.java


示例3: addData

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
@Override
public void addData(CrawleableUri uri, InputStream stream) {
    try {
        addData(uri, StreamUtils.getBytes(stream));
    } catch (IOException e) {
        LOGGER.error("Error while reading data from stream. The data won't be stored.", e);
    }
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:9,代码来源:InMemorySink.java


示例4: addData

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
@Override
public void addData(CrawleableUri uri, InputStream stream) {
    OutputStream outputStream = getStream(uri);
    if (outputStream != null) {
        try {
            StreamUtils.copy(stream, outputStream);
        } catch (Exception e) {
            LOGGER.error("Exception while writing unstructed data to file.", e);
        }
    }
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:12,代码来源:FileBasedSink.java


示例5: getBytesForFileName

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
public byte[] getBytesForFileName(String filename) throws Exception {
    if (Utils.isEmpty(filename)) {
        throw new IllegalArgumentException("File name cannot be null");
    }

    byte[] fileContent = null;
    ByteArrayInputStream bis = new ByteArrayInputStream(getUnpackagedZipFileAsBytes());
    ZipInputStream zis = new ZipInputStream(bis);
    try {
        for (;;) {
            ZipEntry ze = zis.getNextEntry();
            if (ze == null) {
                break;
            }
            fileContent = StreamUtils.getBytes(zis);
            String name = ze.getName();
            if (ze.isDirectory()) {
                continue;
            }

            if (filename.endsWith(name)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Found '" + name + "' body size [" + fileContent.length + "]");
                }
                return fileContent;
            }
        }
    } finally {
        zis.close();
    }
    return fileContent;
}
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:33,代码来源:BaseIDETestCase.java


示例6: createTempJSPFile

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
private void createTempJSPFile(ActionInvocation invocation) throws IOException {
	try {
		if (!jspFileRecreated) {
			InputStream is = getClass().getResourceAsStream("/com/googlecode/s2hibernate/struts2/plugin/pages/management.jsp");
			byte[] bytes = StreamUtils.getBytes(is);
			String jspPath = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("/");
			jspPath+="/WEB-INF/temp/hibernatePlugin/management.jsp";
			FileUtils.writeByteArrayToFile(new File(jspPath), bytes);
			jspFileRecreated=true;
		}
	} catch (IOException e) {
		e.printStackTrace();
		throw new IOException("Unable to create Plugin Management JSP file. "+e.getMessage());
	}
}
 
开发者ID:javalover123,项目名称:full-hibernate-plugin-for-struts2,代码行数:16,代码来源:HibernateManagementInterceptor.java


示例7: updateFile

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
private void updateFile(final File file) throws IOException {
    InputStream is = null;
    OutputStream os = null;
    try {
        is = loader.openResource(pathname);
        os = new BufferedOutputStream(new FileOutputStream(file));
        StreamUtils.copy(is, os);
        os.flush();
    } finally {
        IOUtils.closeWhileHandlingException(is, os);
    }
}
 
开发者ID:codelibs,项目名称:fess-solr-plugin,代码行数:13,代码来源:MonitoringUtil.java


示例8: requestData

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
protected File requestData(CrawleableUri uri, File outputFile)
        throws ClientProtocolException, FileNotFoundException, IOException {
    HttpGet request = null;
    request = new HttpGet(uri.getUri());
    request.addHeader(HttpHeaders.ACCEPT,
            MapUtils.getString(uri.getData(), Constants.URI_HTTP_ACCEPT_HEADER, acceptHeader));
    request.addHeader(HttpHeaders.ACCEPT_CHARSET,
            MapUtils.getString(uri.getData(), Constants.URI_HTTP_ACCEPT_HEADER, acceptCharset));

    HttpEntity entity = null;
    CloseableHttpResponse response = null;
    OutputStream os = null;
    try {
        response = client.execute(request);

        // Handle response headers (especially the status and the content type)
        for (Header header : response.getAllHeaders()) {
            uri.addData(HTTP_RESPONSE_HEADER_PREFIX + header.getName(), header.getValue());
        }
        StatusLine status = response.getStatusLine();
        uri.addData(Constants.URI_HTTP_STATUS_CODE, status.getStatusCode());
        if ((status.getStatusCode() < 200) || (status.getStatusCode() >= 300)) {
            LOGGER.info("Response of \"{}\" has the wrong status ({}). Returning null.", uri, status.toString());
            return null;
        }
        Header contentTypeHeader = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
        if (contentTypeHeader != null) {
            String typeValues[] = contentTypeHeader.getValue().split(";");
            uri.addData(Constants.URI_HTTP_MIME_TYPE_KEY, typeValues[0]);
            // If the content type contains a charset
            if (typeValues.length > 0) {
                uri.addData(Constants.URI_HTTP_CHARSET_KEY, typeValues[1]);
            }
        } else {
            LOGGER.info("The response did not contain a content type header.");
        }

        // store response data
        entity = response.getEntity();
        InputStream is = entity.getContent();
        os = new BufferedOutputStream(new FileOutputStream(outputFile));
        StreamUtils.copy(is, os);
    } finally {
        IOUtils.closeQuietly(os);
        if (entity != null) {
            try {
                EntityUtils.consume(entity);
            } catch (IOException e1) {
            }
        }
        if (response != null) {
            try {
                response.close();
            } catch (IOException e) {
            }
        }
    }
    uri.addData(Constants.URI_DATA_FILE_NAME, outputFile.getAbsolutePath());
    return outputFile;
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:61,代码来源:HTTPFetcher.java


示例9: parseZip

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
public void parseZip(byte[] zipFile, IProgressMonitor monitor) throws IOException {
    if (zipFile == null) {
        throw new IllegalArgumentException("File zip cannot be null");
    }

    if (logger.isDebugEnabled()) {
        ZipUtils.writeRetrieveZipToTempDir(zipFile);
    }

    monitor.subTask("Parsing retrieved zip response...");

    List<String> folderNames = projectService.getComponentFactory().getFolderNamesForFolderComponents();

    try (final QuietCloseable<ZipInputStream> c = QuietCloseable.make(new ZipInputStream(new ByteArrayInputStream(zipFile)))) {
        final ZipInputStream zis = c.get();

        for (;;) {
            ZipEntry ze = zis.getNextEntry();
            if (ze == null) {
                break;
            }

            byte[] fileContent = StreamUtils.getBytes(zis);
            String name = ze.getName();
            if (ze.isDirectory()) {
                continue;
            }

            ProjectPackage projectPackage = null;
            // path starts with package name
            if (startsWithPackageName(folderNames, name)) {
                projectPackage = getProjectPackage(name.split("/")[0]);
            } else if (size() > 0) {
                projectPackage = get(0);
            } else {
                projectPackage = getProjectPackage(Constants.DEFAULT_PACKAGED_NAME);
            }

            if (projectPackage == null) {
                continue;
            }

            projectPackage.addFilePathZipMapping(name, fileContent);
        }
    }

    monitorWork(monitor);
}
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:49,代码来源:ProjectPackageList.java


示例10: handleRequestInternal

import org.apache.log4j.lf5.util.StreamUtils; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
            
    String fileName = request.getParameter("fileName");

    m_reportdConfigurationDao = BeanUtils.getBean("reportdContext", "reportdConfigDao", ReportdConfigurationDao.class);
    final File storageDirectory = new File(m_reportdConfigurationDao.getStorageDirectory());
    
    if (fileName != null) {
        final File requestedFile = new File(fileName);
        if (!requestedFile.getParentFile().getCanonicalFile().equals(storageDirectory.getCanonicalFile())) {
            LogUtils.warnf(this, "User attempted to retrieve file %s but was restricted to %s", requestedFile, storageDirectory);
            throw new IllegalArgumentException("Cannot retrieve reports from outside Reportd storage directory");
        }

        if (fileName.toLowerCase().endsWith(".pdf")) {
            response.setContentType("application/pdf;charset=UTF-8");

        }
        if (fileName.toLowerCase().endsWith(".csv")) {
            response.setContentType("text/csv;charset=UTF-8");
        }
        response.setHeader("Content-disposition", "inline; filename=" + fileName);
        response.setHeader("Pragma", "public");
        response.setHeader("Cache-Control", "cache");
        response.setHeader("Cache-Control", "must-revalidate");
        StreamUtils.copy(new FileInputStream(new File(fileName)), response.getOutputStream());
        return null;
    }

    String[] requiredParameters = new String[] { "locatorId", "format" };

    for (String requiredParameter : requiredParameters) {
        if (request.getParameter(requiredParameter) == null) {
            throw new MissingParameterException(requiredParameter,
                                                requiredParameters);
        }
    }

    try {
        Integer reportCatalogEntryId = Integer.valueOf(WebSecurityUtils.safeParseInt(request.getParameter("locatorId")));
        
        String requestFormat = new String(request.getParameter("format"));

        if ((ReportFormat.PDF == ReportFormat.valueOf(requestFormat))
                || (ReportFormat.SVG == ReportFormat.valueOf(requestFormat)) ) {
            response.setContentType("application/pdf;charset=UTF-8");
            response.setHeader("Content-disposition", "inline; filename="
                               + reportCatalogEntryId.toString()
                               + ".pdf");
            response.setHeader("Pragma", "public");
            response.setHeader("Cache-Control", "cache");
            response.setHeader("Cache-Control", "must-revalidate");
        }
        if(ReportFormat.CSV == ReportFormat.valueOf(requestFormat)) {
            response.setContentType("text/csv;charset=UTF-8");
            response.setHeader("Content-disposition", "inline; filename="
                               + reportCatalogEntryId.toString()
                               + ".csv");
            response.setHeader("Pragma", "public");
            response.setHeader("Cache-Control", "cache");
            response.setHeader("Cache-Control", "must-revalidate");
        }
        m_reportStoreService.render(
                                    reportCatalogEntryId,
                                    ReportFormat.valueOf(requestFormat),
                                    (OutputStream) response.getOutputStream());
    } catch (NumberFormatException e) {
        // TODO something useful here.
    }

    return null;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:76,代码来源:DownloadReportController.java



注:本文中的org.apache.log4j.lf5.util.StreamUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Base64类代码示例发布时间:2022-05-21
下一篇:
Java ConfigUtils类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap