|
|
|
|
@ -16,7 +16,6 @@ import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import cokr.xit.foundation.AbstractComponent;
|
|
|
|
|
import cokr.xit.foundation.AbstractEntity;
|
|
|
|
|
import cokr.xit.foundation.Assert;
|
|
|
|
|
|
|
|
|
|
/**파일 정보
|
|
|
|
|
* @author mjkhan
|
|
|
|
|
@ -35,11 +34,11 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
* @return infoKey
|
|
|
|
|
*/
|
|
|
|
|
public static String InfoKey(Object... objs) {
|
|
|
|
|
if (Assert.isEmpty(objs))
|
|
|
|
|
if (isEmpty(objs))
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
return Stream.of(objs)
|
|
|
|
|
.filter(obj -> !Assert.isEmpty(obj))
|
|
|
|
|
.filter(obj -> !isEmpty(obj))
|
|
|
|
|
.map(obj -> obj.toString())
|
|
|
|
|
.collect(Collectors.joining("-"));
|
|
|
|
|
}
|
|
|
|
|
@ -96,9 +95,9 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
* @param fileInfo FileInfo
|
|
|
|
|
*/
|
|
|
|
|
public void setInfo(FileInfo fileInfo) {
|
|
|
|
|
fileInfo.setInfoType(Assert.notEmpty(infoType, "infoType"));
|
|
|
|
|
fileInfo.setInfoKey(Assert.notEmpty(infoKey, "infoKey"));
|
|
|
|
|
if (!Assert.isEmpty(subType))
|
|
|
|
|
fileInfo.setInfoType(notEmpty(infoType, "infoType"));
|
|
|
|
|
fileInfo.setInfoKey(notEmpty(infoKey, "infoKey"));
|
|
|
|
|
if (!isEmpty(subType))
|
|
|
|
|
fileInfo.setSubType(subType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -128,7 +127,7 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
* @param data 파일 데이터
|
|
|
|
|
*/
|
|
|
|
|
public DataHolder(Relation relation, String filename, String data) {
|
|
|
|
|
this(relation, filename, !Assert.isEmpty(data) ? Base64.getDecoder().decode(data.getBytes()) : null);
|
|
|
|
|
this(relation, filename, !FileInfo.isEmpty(data) ? Base64.getDecoder().decode(data.getBytes()) : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**관계 정보를 반환한다.
|
|
|
|
|
@ -447,7 +446,7 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
* @return mime type
|
|
|
|
|
*/
|
|
|
|
|
public String getMimeType() {
|
|
|
|
|
return Assert.ifEmpty(mimeType, () -> mimeType = "application/octet-stream");
|
|
|
|
|
return ifEmpty(mimeType, () -> mimeType = "application/octet-stream");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**mime type을 설정한다.
|
|
|
|
|
@ -461,7 +460,7 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
* @return 확장자
|
|
|
|
|
*/
|
|
|
|
|
public String getExtension() {
|
|
|
|
|
return Assert.ifEmpty(extension, () -> extension = extension(name));
|
|
|
|
|
return ifEmpty(extension, () -> extension = extension(name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**확장자를 설정한다.
|
|
|
|
|
@ -535,12 +534,12 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
public InputStream getInputStream() {
|
|
|
|
|
if (input != null) return input;
|
|
|
|
|
|
|
|
|
|
if (Assert.isEmpty(path)) return null;
|
|
|
|
|
if (isEmpty(path)) return null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return new FileInputStream(path);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw Assert.runtimeException(e);
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -569,7 +568,7 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
in.transferTo(out);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw Assert.runtimeException(e);
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -583,7 +582,7 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
try (FileOutputStream out = new FileOutputStream(path)) {
|
|
|
|
|
return write(out);
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
throw Assert.runtimeException(e);
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -594,7 +593,7 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
* </ul>
|
|
|
|
|
*/
|
|
|
|
|
public boolean delete() {
|
|
|
|
|
if (Assert.isEmpty(path)) return false;
|
|
|
|
|
if (isEmpty(path)) return false;
|
|
|
|
|
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
return file.exists() ? file.delete() : false;
|
|
|
|
|
@ -610,13 +609,13 @@ public class FileInfo extends AbstractEntity {
|
|
|
|
|
input = null;
|
|
|
|
|
return this;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw Assert.runtimeException(e);
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
String path = getPath();
|
|
|
|
|
return getName() + (Assert.isEmpty(path) ? "" : " -> " + path);
|
|
|
|
|
return getName() + (isEmpty(path) ? "" : " -> " + path);
|
|
|
|
|
}
|
|
|
|
|
}
|