java中文件FileInfo工具类

该博客介绍了一个Java实现的FileInfo类,用于处理文件信息。类中包含了文件名、类型、文档类型、文件小类别、订单号、后缀、文件ID、文件资源路径等属性,并提供了设置和获取这些属性的方法。此外,FileInfo类还包含了一个子目录列表,用于存储子文件信息,并实现了路径的计算和修正功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;

public class FileInfo extends BaseDto {
 
 private static final long serialVersionUID =      ;

 //名称
 @JSONField(name="imageName")
 public String name;
 
 //类型
 @JSONField(name="type")
 private String type;
 
 @JSONField(name="documentType")
 private String documentType;
 
 //文件小类别
 @JSONField(name="fileType")
 private String fileType;
  
 //订单号
 @JSONField(name="idOrder")
 private String idOrder;
 
 //文件后缀
 @JSONField(name="ext")
 private String ext;
 
 //文件id
 @JSONField(name="fileId")
 private String fileId;
 
 //文件资源路径
 @JSONField(name="fileUri")
 private String fileUri;
 
 @JSONField(name="fileUrl")
 private String fileUrl;
 
 //父级文件夹位置
 @JSONField(name="fileParentPath")
 private String fileParentPath="";

 //子目录
 @JSONField(name="children")
 private List<FileInfo> children;

 public FileInfo(){
  this.children = new ArrayList<FileInfo>();
 }
 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public String getType() {
  return type;
 }

 public void setType(String type) {
  this.type = type;
 }

 public String getIdOrder() {
  return idOrder;
 }

 public void setIdOrder(String idOrder) {
  this.idOrder = idOrder;
 }

 public String getExt() {
  return ext;
 }

 public void setExt(String ext) {
  this.ext = ext;
 }

 public String getFileId() {
  return fileId;
 }

 public void setFileId(String fileId) {
  this.fileId = fileId;
 }

 public String getFileUri() {
  return fileUri;
 }

 public void setFileUri(String fileUri) {
  this.fileUri = fileUri;
 }

 public String getFilePath() {
  StringBuffer path = new StringBuffer( (null != this.fileParentPath) ? this.fileParentPath:"" );
  path.append(File.separator);
  path.append(this.name);
  if( this.ext != null && !this.ext.isEmpty()){
   path.append(".");
   path.append( this.ext );
  }
  
  return path.toString();
 }

 public List<FileInfo> getChildren() {
  return children;
 }

 public void setChildren(List<FileInfo> children) {
  if(children != null && !children.isEmpty()){
   for(FileInfo child : children){
    child.idOrder = this.idOrder;
    fixPath(child, this.fileParentPath, this.name);
   }
   
   this.children = children;
  }
 }
 
 public void addChild(FileInfo child){
  if(child==null){
   return;
  }
  child.idOrder = this.idOrder;
  fixPath(child, this.fileParentPath, this.name);
  this.children.add(child);
 }
 
 public void fixPath(FileInfo child, String baseParentPath, String baseName){
  if(child == null || baseParentPath == null || baseName == null){
   return;
  }
  
  
  child.fileParentPath = baseParentPath + File.separator + baseName;
    
  
  if(child.getChildren() != null){
   for(FileInfo innerChild : child.getChildren()){
    fixPath(innerChild, child.fileParentPath, child.name);
   }
  }
  
 }
 
 public String getFileParentPath() {
  return fileParentPath;
 }

 public void setFileParentPath(String fileParentPath) {
  this.fileParentPath = fileParentPath;
 }

 public String getDocumentType() {
  return documentType;
 }
 
 public void setDocumentType(String documentType) {
  this.documentType = documentType;
 }
 
 public String getFileType() {
  return fileType;
 }
 
 public void setFileType(String fileType) {
  this.fileType = fileType;
 }
 
 public String getFileUrl() {
  return fileUrl;
 }
 
 public void setFileUrl(String fileUrl) {
  this.fileUrl = fileUrl;
 }
 
 @Override
 public boolean equals(Object object){
  if(object == null){
   return false;
  }
  if(! ( object instanceof FileInfo)){
   return false;
  }
  
  FileInfo fileObj = (FileInfo)object;
  if(fileObj.fileId == null || fileObj.fileId.isEmpty() || this.fileId == null || this.fileId.isEmpty()){
   return false;
  }else if(this.fileId.equals(fileObj.fileId)){
   return true;
  }
  return false;
 }
 
 @Override
 public int hashCode(){
  return 0;
 }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值