NIMSDK-AOS  10.9.80
V2NIMMessageFileAttachmentBuilder.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.message.attachment.builder;
2 
4 import com.netease.nimlib.v2.message.impl.attachment.V2NIMMessageFileAttachmentImpl;
5 
6 /**
7  * V2NIMMessageFileAttachmentBuilder 类
8  *
9  * 这个类用于构建文件附件消息。它使用了构建器模式,允许用户通过链式调用设置各种属性。
10  */
12 
13  /**
14  * 文件路径
15  */
16  private String path;
17  /**
18  * 文件显示名称
19  */
20  private String name;
21  /**
22  * 文件大小
23  */
24  private long size;
25  /**
26  * 文件存储场景名
27  * 默认为{@link com.netease.nimlib.sdk.v2.storage.V2NIMStorageSceneConfig#DEFAULT_IM}的getSceneName()值
28  */
29  private String sceneName = V2NIMStorageSceneConfig.DEFAULT_IM.getSceneName();
30  /**
31  * 文件MD5
32  */
33  private String md5;
34  /**
35  * 文件上传服务器路径
36  */
37  private String url;
38  /**
39  * 文件后缀名
40  */
41  private String ext;
42 
43  /**
44  * 私有构造函数,防止直接实例化
45  */
47  }
48 
49  /**
50  * 创建一个新的V2NIMMessageFileAttachmentBuilder实例
51  *
52  * @return 新的V2NIMMessageFileAttachmentBuilder实例
53  */
56  }
57 
58  /**
59  * 设置文件路径
60  *
61  * @param path 文件路径
62  * @return 当前构建器实例
63  */
65  this.path = path;
66  return this;
67  }
68 
69  /**
70  * 设置文件名称
71  *
72  * @param name 文件名称
73  * @return 当前构建器实例
74  */
76  this.name = name;
77  return this;
78  }
79 
80  /**
81  * 设置文件大小,如果小于0,则不设置
82  *
83  * @param size 文件大小(字节)
84  * @return 当前构建器实例
85  */
87  if (size >= 0) {
88  this.size = size;
89  }
90  return this;
91  }
92 
93  /**
94  * 设置文件存储场景名,默认为{@link com.netease.nimlib.sdk.v2.storage.V2NIMStorageSceneConfig#DEFAULT_IM}的getSceneName()值
95  * @param sceneName 存储场景名
96  * @return 当前构建器实例
97  */
99  this.sceneName = sceneName;
100  return this;
101  }
102 
103  /**
104  * 设置文件MD5
105  *
106  * @param md5 文件MD5值
107  * @return 当前构建器实例
108  */
110  this.md5 = md5;
111  return this;
112  }
113 
114  /**
115  * 设置文件URL
116  *
117  * @param url 文件上传服务器路径
118  * @return 当前构建器实例
119  */
121  this.url = url;
122  return this;
123  }
124 
125  /**
126  * 设置文件扩展名
127  *
128  * @param ext 文件扩展名
129  * @return 当前构建器实例
130  */
132  this.ext = ext;
133  return this;
134  }
135 
136  /**
137  * 构建V2NIMMessageFileAttachmentImpl实例
138  *
139  * @return 新的V2NIMMessageFileAttachmentImpl实例
140  */
141  public V2NIMMessageFileAttachmentImpl build() {
142  return new V2NIMMessageFileAttachmentImpl(path, size, md5, url, ext, name, sceneName, null);
143  }
144 }
V2NIMMessageFileAttachmentBuilder withSize(long size)
设置文件大小,如果小于0,则不设置
V2NIMMessageFileAttachmentImpl build()
构建V2NIMMessageFileAttachmentImpl实例
static V2NIMMessageFileAttachmentBuilder builder()
创建一个新的V2NIMMessageFileAttachmentBuilder实例
V2NIMMessageFileAttachmentBuilder withSceneName(String sceneName)
设置文件存储场景名,默认为com.netease.nimlib.sdk.v2.storage.V2NIMStorageSceneConfig#DEFAULT_IM的getSc...
static final V2NIMStorageScene DEFAULT_IM
默认文件类型等场景 默认不过期