NIMSDK-AOS  10.9.80
V2NIMMessageImageAttachmentBuilder.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.message.attachment.builder;
2 
5 import com.netease.nimlib.v2.message.impl.attachment.V2NIMMessageImageAttachmentImpl;
6 
7 /**
8  * V2NIMMessageImageAttachmentBuilder类
9  *
10  * 用于构建图片消息附件的构建器类。
11  * 此类使用建造者模式,允许链式调用设置各种属性。
12  */
14 
15  /**
16  * 文件路径
17  */
18  private String path;
19  /**
20  * 文件显示名称
21  */
22  private String name;
23  /**
24  * 文件大小
25  */
26  private long size;
27  /**
28  * 文件存储场景名
29  * 默认为{@link com.netease.nimlib.sdk.v2.storage.V2NIMStorageSceneConfig#DEFAULT_IM}的getSceneName()值
30  */
31  private String sceneName = V2NIMStorageSceneConfig.DEFAULT_IM.getSceneName();
32  /**
33  * 文件MD5
34  */
35  private String md5;
36  /**
37  * 文件上传服务器路径
38  */
39  private String url;
40  /**
41  * 文件后缀名
42  */
43  private String ext;
44  /**
45  * 图片宽度
46  */
47  private int width;
48  /**
49  * 图片高度
50  */
51  private int height;
52 
53  /**
54  * 私有构造函数,防止直接实例化
55  */
57  }
58 
59  /**
60  * 创建一个新的V2NIMMessageImageAttachmentBuilder实例
61  *
62  * @return 新的V2NIMMessageImageAttachmentBuilder实例
63  */
66  }
67 
68  /**
69  * 设置文件路径
70  *
71  * @param path 文件路径
72  * @return 当前构建器实例
73  */
75  this.path = path;
76  return this;
77  }
78 
79  /**
80  * 设置文件名称
81  *
82  * @param name 文件名称
83  * @return 当前构建器实例
84  */
86  this.name = name;
87  return this;
88  }
89 
90  /**
91  * 设置文件大小,如果小于0,则不设置
92  *
93  * @param size 文件大小
94  * @return 当前构建器实例
95  */
97  if (size >= 0) {
98  this.size = size;
99  }
100  return this;
101  }
102 
103  /**
104  * 设置文件存储场景名,默认为{@link com.netease.nimlib.sdk.v2.storage.V2NIMStorageSceneConfig#DEFAULT_IM}的getSceneName()值
105  * @param sceneName 存储场景名
106  * @return 当前构建器实例
107  */
109  this.sceneName = sceneName;
110  return this;
111  }
112 
113  /**
114  * 设置文件MD5
115  *
116  * @param md5 文件MD5值
117  * @return 当前构建器实例
118  */
120  this.md5 = md5;
121  return this;
122  }
123 
124  /**
125  * 设置文件上传服务器路径
126  *
127  * @param url 服务器路径
128  * @return 当前构建器实例
129  */
131  this.url = url;
132  return this;
133  }
134 
135  /**
136  * 设置文件后缀名
137  *
138  * @param ext 文件后缀名
139  * @return 当前构建器实例
140  */
142  this.ext = ext;
143  return this;
144  }
145 
146  /**
147  * 设置图片宽度,如果小于0,则不设置
148  *
149  * @param width 图片宽度
150  * @return 当前构建器实例
151  */
153  if (width >= 0) {
154  this.width = width;
155  }
156  return this;
157  }
158 
159  /**
160  * 设置图片高度,如果小于0,则不设置
161  *
162  * @param height 图片高度
163  * @return 当前构建器实例
164  */
166  if (height >= 0) {
167  this.height = height;
168  }
169  return this;
170  }
171 
172  /**
173  * 构建V2NIMMessageImageAttachment实例
174  *
175  * @return 新的V2NIMMessageImageAttachment实例
176  */
178  return new V2NIMMessageImageAttachmentImpl(path, size, md5, url, ext, name, sceneName, null, width, height);
179  }
180 }
static V2NIMMessageImageAttachmentBuilder builder()
创建一个新的V2NIMMessageImageAttachmentBuilder实例
V2NIMMessageImageAttachmentBuilder withSceneName(String sceneName)
设置文件存储场景名,默认为com.netease.nimlib.sdk.v2.storage.V2NIMStorageSceneConfig#DEFAULT_IM的getSc...
V2NIMMessageImageAttachmentBuilder withUrl(String url)
设置文件上传服务器路径
V2NIMMessageImageAttachmentBuilder withWidth(int width)
设置图片宽度,如果小于0,则不设置
static final V2NIMStorageScene DEFAULT_IM
默认文件类型等场景 默认不过期
V2NIMMessageImageAttachmentBuilder withSize(long size)
设置文件大小,如果小于0,则不设置
V2NIMMessageImageAttachmentBuilder withHeight(int height)
设置图片高度,如果小于0,则不设置