|
|
@ -9,12 +9,12 @@ import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.poi.util.DefaultTempFileCreationStrategy; |
|
|
|
|
|
|
|
import org.apache.poi.util.TempFile; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.exception.ExcelAnalysisException; |
|
|
|
import com.alibaba.excel.exception.ExcelAnalysisException; |
|
|
|
import com.alibaba.excel.exception.ExcelCommonException; |
|
|
|
import com.alibaba.excel.exception.ExcelCommonException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.poi.util.DefaultTempFileCreationStrategy; |
|
|
|
|
|
|
|
import org.apache.poi.util.TempFile; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* @author jipengfei |
|
|
|
* @author jipengfei |
|
|
@ -100,10 +100,21 @@ public class FileUtils { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Write inputStream to file |
|
|
|
* Write inputStream to file |
|
|
|
* |
|
|
|
* |
|
|
|
* @param file |
|
|
|
* @param file file |
|
|
|
* @param inputStream |
|
|
|
* @param inputStream inputStream |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void writeToFile(File file, InputStream inputStream) { |
|
|
|
public static void writeToFile(File file, InputStream inputStream) { |
|
|
|
|
|
|
|
writeToFile(file, inputStream, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Write inputStream to file |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param file file |
|
|
|
|
|
|
|
* @param inputStream inputStream |
|
|
|
|
|
|
|
* @param closeInputStream closeInputStream |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void writeToFile(File file, InputStream inputStream, boolean closeInputStream) { |
|
|
|
OutputStream outputStream = null; |
|
|
|
OutputStream outputStream = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
outputStream = new FileOutputStream(file); |
|
|
|
outputStream = new FileOutputStream(file); |
|
|
@ -122,7 +133,7 @@ public class FileUtils { |
|
|
|
throw new ExcelAnalysisException("Can not close 'outputStream'!", e); |
|
|
|
throw new ExcelAnalysisException("Can not close 'outputStream'!", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (inputStream != null) { |
|
|
|
if (inputStream != null && closeInputStream) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
inputStream.close(); |
|
|
|
inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
@ -132,27 +143,6 @@ public class FileUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void writeToFileNotCloseStream(File file, InputStream inputStream) { |
|
|
|
|
|
|
|
OutputStream outputStream = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
outputStream = new FileOutputStream(file); |
|
|
|
|
|
|
|
int bytesRead; |
|
|
|
|
|
|
|
byte[] buffer = new byte[WRITE_BUFF_SIZE]; |
|
|
|
|
|
|
|
while ((bytesRead = inputStream.read(buffer, 0, WRITE_BUFF_SIZE)) != -1) { |
|
|
|
|
|
|
|
outputStream.write(buffer, 0, bytesRead); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
throw new ExcelAnalysisException("Can not create temporary file!", e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
if (outputStream != null) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
outputStream.close(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
throw new ExcelAnalysisException("Can not close 'outputStream'!", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void createPoiFilesDirectory() { |
|
|
|
public static void createPoiFilesDirectory() { |
|
|
|
File poiFilesPathFile = new File(poiFilesPath); |
|
|
|
File poiFilesPathFile = new File(poiFilesPath); |
|
|
|