案例管理
This commit is contained in:
@ -1,11 +1,6 @@
|
||||
package com.stdiet.common.utils.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@ -74,6 +69,55 @@ public class FileUtils extends org.apache.commons.io.FileUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出指定文件的byte数组
|
||||
*
|
||||
* @param inputStream 输入流
|
||||
* @param os 输出流
|
||||
* @return
|
||||
*/
|
||||
public static void writeBytes(InputStream inputStream, OutputStream os) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] b = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(b)) > 0)
|
||||
{
|
||||
os.write(b, 0, length);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (os != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
os.close();
|
||||
}
|
||||
catch (IOException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (inputStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
|
@ -13,20 +13,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AliyunOSSUtils {
|
||||
|
||||
// 创建OSSClient实例
|
||||
private static OSS ossClient = null;
|
||||
public class AliyunOSSUtils { ;
|
||||
|
||||
public static OSS getOssClient() {
|
||||
if (ossClient == null) {
|
||||
synchronized (OSS.class) {
|
||||
if (ossClient == null) {
|
||||
ossClient = new OSSClientBuilder().build(AliyunOSSConfig.EndPoint, AliyunOSSConfig.AccessKeyID, AliyunOSSConfig.AccessKeySecret);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ossClient;
|
||||
return new OSSClientBuilder().build(AliyunOSSConfig.EndPoint, AliyunOSSConfig.AccessKeyID, AliyunOSSConfig.AccessKeySecret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,7 +194,7 @@ public class AliyunOSSUtils {
|
||||
*
|
||||
* @param fileURL 文件的url
|
||||
*/
|
||||
public InputStream downloadFile(String fileURL) throws IOException {
|
||||
public static InputStream downloadFile(String fileURL) throws IOException {
|
||||
|
||||
//将url解析成objectName
|
||||
String objectName = getObjectName(fileURL);
|
||||
|
Reference in New Issue
Block a user