use of com.varsql.core.exception.FileNotFoundException in project varsql by varsqlinfo.
the class FileServiceUtils method getFileInfos.
/**
* @method : fileInfos
* @desc : file info 구하기
* @author : ytkim
* @date : 2022. 1. 15.
* @param FilePaths
* @return
* @throws IOException
*/
public static List<FileInfo> getFileInfos(String[] FilePaths) throws IOException {
List<FileInfo> driverJarFiles = new ArrayList<>();
for (String path : FilePaths) {
Resource resource = ResourceUtils.getResource(path);
if (resource != null) {
FileInfo fi = new FileInfo();
fi.setName(resource.getFile().getName());
fi.setPath(resource.getFile().getAbsolutePath());
fi.setExt(FileUtils.extension(resource.getFile().getName()));
driverJarFiles.add(fi);
} else {
throw new FileNotFoundException("file path not found : " + path);
}
}
return driverJarFiles;
}
use of com.varsql.core.exception.FileNotFoundException in project varsql by varsqlinfo.
the class UserPreferencesServiceFileImpl method zipFileDetail.
public ResponseResult zipFileDetail(String fileId, String fileName) {
FileInfoEntity entity = fileInfoEntityRepository.findByFileId(fileId);
if (entity == null) {
new FileNotFoundException("fileId not found : " + fileId);
}
StringBuffer sb = new StringBuffer();
try (ZipFile zipFile = new ZipFile(FileServiceUtils.getFileInfoToFile(entity))) {
ZipEntry entry = zipFile.getEntry(fileName);
if (entry.getName().equals(fileName)) {
try (InputStreamReader isr = new InputStreamReader(zipFile.getInputStream(entry));
BufferedReader br = new BufferedReader(isr)) {
String read_data = "";
int lineCount = 0;
while ((read_data = br.readLine()) != null) {
if (lineCount >= MAX_LINE) {
break;
}
lineCount++;
sb.append(read_data).append(BlankConstants.NEW_LINE);
}
IOUtils.close(br);
IOUtils.close(isr);
}
}
IOUtils.close(zipFile);
} catch (Exception e) {
logger.error("detail fileId : {}", fileId, e);
}
return VarsqlUtils.getResponseResultItemOne(sb.toString());
}
use of com.varsql.core.exception.FileNotFoundException in project varsql by varsqlinfo.
the class UserPreferencesServiceFileImpl method detail.
public ResponseResult detail(String fileId) {
FileInfoEntity entity = fileInfoEntityRepository.findByFileId(fileId);
if (entity == null) {
new FileNotFoundException("fileId not found : " + fileId);
}
if (UploadFileType.EXPORT.equals(UploadFileType.getDivType(entity.getFileDiv()))) {
Map item;
List<Map> fileList = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(FileServiceUtils.getFileInfoToFile(entity))) {
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
item = new HashMap();
item.put("fileName", entry.getName());
item.put("fileSize", entry.getSize());
item.put("compressFileSize", entry.getCompressedSize());
item.put("updDt", DateUtils.dateformat(VarsqlConstants.DATE_TIME_FORMAT, entry.getLastModifiedTime().toMillis()));
fileList.add(item);
}
IOUtils.close(zipFile);
} catch (Exception e) {
logger.error("detail fileId : {}", fileId, e);
}
return VarsqlUtils.getResponseResultItemList(fileList);
} else if (UploadFileType.IMPORT.equals(UploadFileType.getDivType(entity.getFileDiv()))) {
StringBuffer sb = new StringBuffer();
Map item = new HashMap();
try (InputStreamReader isr = new InputStreamReader(new FileInputStream(FileServiceUtils.getFileInfoToFile(entity)));
BufferedReader br = new BufferedReader(isr)) {
String read_data = "";
int lineCount = 0;
while ((read_data = br.readLine()) != null) {
if (lineCount >= MAX_LINE) {
break;
}
lineCount++;
sb.append(read_data).append(BlankConstants.NEW_LINE);
}
item.put("lineCount", lineCount);
item.put("content", sb.toString());
IOUtils.close(br);
IOUtils.close(isr);
} catch (Exception e) {
logger.error("detail fileId : {}", fileId, e);
}
return VarsqlUtils.getResponseResultItemOne(item);
}
return VarsqlUtils.getResponseResultItemOne(null);
}
use of com.varsql.core.exception.FileNotFoundException in project varsql by varsqlinfo.
the class FileServiceUtils method loadFileAsResource.
/**
* @method : loadFileAsResource
* @desc : file nam
* @author : ytkim
* @date : 2021. 1. 3.
* @param fileName
* @return
* @throws MalformedURLException
*/
public static Resource loadFileAsResource(String filePath) throws MalformedURLException {
Path path = getUploadRootPath().resolve(filePath).normalize();
Resource resource = new UrlResource(path.toUri());
if (resource.exists()) {
return resource;
} else {
throw new FileNotFoundException("File resource not found " + filePath);
}
}
Aggregations