本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java IOUtils.copy怎么用?Java IOUtils.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildMetadataGeneratorParameters
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Build metadata generator parameters by passing the encryption,
* signing and back-channel certs to the parameter generator.
*
* @throws Exception Thrown if cert files are missing, or metadata file inaccessible.
*/
protected void buildMetadataGeneratorParameters() throws Exception {
final SamlIdPProperties idp = casProperties.getAuthn().getSamlIdp();
final Resource template = this.resourceLoader.getResource("classpath:/template-idp-metadata.xml");
String signingKey = FileUtils.readFileToString(idp.getMetadata().getSigningCertFile().getFile(), StandardCharsets.UTF_8);
signingKey = StringUtils.remove(signingKey, BEGIN_CERTIFICATE);
signingKey = StringUtils.remove(signingKey, END_CERTIFICATE).trim();
String encryptionKey = FileUtils.readFileToString(idp.getMetadata().getEncryptionCertFile().getFile(), StandardCharsets.UTF_8);
encryptionKey = StringUtils.remove(encryptionKey, BEGIN_CERTIFICATE);
encryptionKey = StringUtils.remove(encryptionKey, END_CERTIFICATE).trim();
try (StringWriter writer = new StringWriter()) {
IOUtils.copy(template.getInputStream(), writer, StandardCharsets.UTF_8);
final String metadata = writer.toString()
.replace("${entityId}", idp.getEntityId())
.replace("${scope}", idp.getScope())
.replace("${idpEndpointUrl}", getIdPEndpointUrl())
.replace("${encryptionKey}", encryptionKey)
.replace("${signingKey}", signingKey);
FileUtils.write(idp.getMetadata().getMetadataFile(), metadata, StandardCharsets.UTF_8);
}
}
示例2: setUp
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
// resource file
this.jsonResource = "org/apache/geode/security/templates/security.json";
InputStream inputStream = ClassLoader.getSystemResourceAsStream(this.jsonResource);
assertThat(inputStream).isNotNull();
// non-resource file
this.jsonFile = new File(temporaryFolder.getRoot(), "security.json");
IOUtils.copy(inputStream, new FileOutputStream(this.jsonFile));
// string
this.json = FileUtils.readFileToString(this.jsonFile, "UTF-8");
this.exampleSecurityManager = new ExampleSecurityManager();
}
示例3: getDataSinkForOpenPgpDecryptedInlineData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private OpenPgpDataSink<MimeBodyPart> getDataSinkForOpenPgpDecryptedInlineData() {
return new OpenPgpDataSink<MimeBodyPart>() {
@Override
public MimeBodyPart processData(InputStream is) throws IOException {
try {
ByteArrayOutputStream decryptedByteOutputStream = new ByteArrayOutputStream();
IOUtils.copy(is, decryptedByteOutputStream);
TextBody body = new TextBody(new String(decryptedByteOutputStream.toByteArray()));
return new MimeBodyPart(body, "text/plain");
} catch (MessagingException e) {
Timber.e(e, "MessagingException");
}
return null;
}
};
}
示例4: getConsole
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Return a snapshot of the console.
*
* @param subscription
* the valid screenshot of the console.
* @return the valid screenshot of the console.
*/
@GET
@Path("{subscription:\\d+}/console.png")
@Produces("image/png")
public StreamingOutput getConsole(@PathParam("subscription") final int subscription) {
final Map<String, String> parameters = subscriptionResource.getParameters(subscription);
final VCloudCurlProcessor processor = new VCloudCurlProcessor();
authenticate(parameters, processor);
// Get the screen thumbnail
return output -> {
final String url = StringUtils.appendIfMissing(parameters.get(PARAMETER_API), "/") + "vApp/vm-" + parameters.get(PARAMETER_VM)
+ "/screen";
final CurlRequest curlRequest = new CurlRequest("GET", url, null, (request, response) -> {
if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
// Copy the stream
IOUtils.copy(response.getEntity().getContent(), output);
output.flush();
}
return false;
});
processor.process(curlRequest);
};
}
示例5: getAuthorizedPhoto
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value="/{eppn}/restrictedPhoto")
public void getAuthorizedPhoto(@PathVariable String eppn, HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
List<Card> validCards = Card.findCardsByEppnAndEtatNotEquals(eppn, Etat.REJECTED, "dateEtat", "desc").getResultList();
if(!validCards.isEmpty()) {
Card card = validCards.get(0);
User user = User.findUser(eppn);
if(user.getDifPhoto()) {
PhotoFile photoFile = card.getPhotoFile();
Long size = photoFile.getFileSize();
String contentType = photoFile.getContentType();
response.setContentType(contentType);
response.setContentLength(size.intValue());
IOUtils.copy(photoFile.getBigFile().getBinaryFile().getBinaryStream(), response.getOutputStream());
}else{
ClassPathResource noImg = new ClassPathResource(ManagerCardController.IMG_INTERDIT);
IOUtils.copy(noImg.getInputStream(), response.getOutputStream());
}
}
}
示例6: processFolder
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static void processFolder(final File folder, final ZipOutputStream zipOutputStream, final int prefixLength)
throws IOException {
for (final File file : folder.listFiles()) {
if (file.isFile()) {
final ZipEntry zipEntry = new ZipEntry(file.getPath().substring(prefixLength));
zipOutputStream.putNextEntry(zipEntry);
try (FileInputStream inputStream = new FileInputStream(file)) {
IOUtils.copy(inputStream, zipOutputStream);
}
zipOutputStream.closeEntry();
} else if (file.isDirectory()) {
processFolder(file, zipOutputStream, prefixLength);
}
}
}
示例7: streamDocumentContentVersion
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void streamDocumentContentVersion(@NotNull DocumentContentVersion documentContentVersion) {
if (documentContentVersion.getDocumentContent() == null || documentContentVersion.getDocumentContent().getData() == null) {
throw new CantReadDocumentContentVersionBinaryException("File content is null", documentContentVersion);
}
try {
response.setHeader(HttpHeaders.CONTENT_TYPE, documentContentVersion.getMimeType());
response.setHeader(HttpHeaders.CONTENT_LENGTH, documentContentVersion.getSize().toString());
response.setHeader("OriginalFileName", documentContentVersion.getOriginalDocumentName());
IOUtils.copy(documentContentVersion.getDocumentContent().getData().getBinaryStream(), response.getOutputStream(), streamBufferSize);
} catch (Exception e) {
throw new CantReadDocumentContentVersionBinaryException(e, documentContentVersion);
}
}
示例8: responseBody
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private String responseBody(RequestContext context) throws IOException {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(STREAM_BUFFER_SIZE.get())) {
IOUtils.copy(context.getResponseDataStream(), outputStream);
context.setResponseBody(outputStream.toString());
return outputStream.toString();
}
}
示例9: execute
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String path=req.getContextPath()+URuleServlet.URL+URL;
String uri=req.getRequestURI();
String resPath=uri.substring(path.length()+1);
String p="classpath:"+resPath;
if(p.endsWith(".js")){
resp.setContentType("text/javascript");
}else if(p.endsWith(".css")){
resp.setContentType("text/css");
}else if(p.endsWith(".png")){
resp.setContentType("image/png");
}else if(p.endsWith(".jpg")){
resp.setContentType("image/jpeg");
}else{
resp.setContentType("application/octet-stream");
}
InputStream input=applicationContext.getResource(p).getInputStream();
OutputStream output=resp.getOutputStream();
try{
IOUtils.copy(input, output);
}finally{
if(input!=null){
input.close();
}
if(output!=null){
output.flush();
output.close();
}
}
}
示例10: copyFileToBin
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static void copyFileToBin(String fileName, InputStream inputStream) {
binFolder.mkdirs();
File copy = new File(binFolder, fileName);
try
{
if(copy.exists())
copy.delete();
FileOutputStream outputStream = new FileOutputStream(copy);
IOUtils.copy(inputStream, outputStream);
}
catch (IOException e) {e.printStackTrace();}
}
示例11: nextPart
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public MimePart nextPart(OutputStream os) throws IOException, MessagingException {
MimeBodyPart bodyPart = readHeaders();
if (bodyPart != null) {
IOUtils.copy(pis, os);
pis.nextPart();
}
return bodyPart;
}
示例12: copyImages
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void copyImages() throws IOException {
File imagesDir = new File(basedir, "images");
imagesDir.mkdirs();
for(File file : listFiles()){
IOUtils.copy(new FileInputStream(file), new FileOutputStream(new File(imagesDir, file.getName())));
}
}
示例13: readStream
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private static String readStream(InputStream stream) throws IOException {
if (stream == null) {
return "";
}
try (StringWriter writer = new StringWriter()){
IOUtils.copy(stream, writer, "UTF-8");
return writer.toString();
}
}
示例14: sendImage
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void sendImage(File file, HttpServletResponse response) throws IOException {
response.setContentType(StringUtil.getMimeType(FilenameUtils.getExtension(file.getName())));
InputStream in = new FileInputStream(file);
try {
IOUtils.copy(in, response.getOutputStream());
} finally {
IOUtils.closeQuietly(in);
}
}
示例15: tagStorage
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Bean
public TagStorage tagStorage(Preferences preferences) throws Exception {
new File(preferences.getDataDir(), "misc").mkdirs();
File file = new File(preferences.getDataDir(), TagStorage.DOCKER_IMAGE_TAGS);
InputStream input = getClass().getResourceAsStream("/kubernetes/base-image-mapper/docker-tagbase.json");
FileOutputStream out = new FileOutputStream(file);
IOUtils.copy(input, out);
input.close();
out.close();
return new TagStorage(preferences);
}