2021SC@SDUSC
目录
Util:
MIMEUtils:
1.总结:
文件、URL和文件名实用程序方法的集合。
2.方法:
static String getDefaultExtension(String type)
返回给定MIME类型的默认文件扩展名。
static String getMIMEType(File file)
返回给定文件的MIME类型。
static String getMIMEType(String ext)
返回给定文件扩展名的MIME类型。
static void loadMimeTypes(Reader in, Map extMap, Map mimeMap)
解析mime.types文件,并在mime类型和扩展名之间生成映射。
NetUtils:
1.总结:
static String absolutize(String path, String resource)
在给定的绝对基本路径上绝对化相对资源路径。
static String decode(String s, String enc)
传递到URL解码器。
static String decodePath(String path)
解码路径。
static String deparameterize(String uri, Map parameters)
从uri中删除参数。
static String encode(String s, String enc)
传递到URL编码器。
static String encodePath(String path)
按照URL规范(RFC 1738)的要求对路径进行编码。
static String getExtension(String uri)
从仅返回扩展名组件的文件名中删除路径和文件信息
static String getPath(String uri)
返回给定资源的路径。
static String normalize(String uri)
规范化包含../和./路径的uri。
static String parameterize(String uri, Map parameters)
将存储在映射中的参数添加到uri字符串。
static String relativize(String path, String absoluteResource)
在给定的绝对路径上相对化绝对资源。
static String removeAuthorisation(String uri)
从URI中删除任何授权详细信息
3.方法详细:
public static String decodePath(String path) {
StringBuffer translatedPath = new StringBuffer(path.length());
byte[] encodedchars = new byte[path.length() / 3];
int i = 0;
int length = path.length();
int encodedcharsLength = 0;
while (i < length) {
if (path.charAt(i) == '%') {
while (i < length && path.charAt(i) == '%') {
if (i + 2 < length) {
try {
byte x = (byte)Integer.parseInt(path.substring(i + 1, i + 3), 16);
encodedchars[encodedcharsLength] = x;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("NetUtils.decodePath: " +
"Illegal hex characters in pattern %" + path.substring(i + 1, i + 3));
}
encodedcharsLength++;
i += 3;
} else {
throw new IllegalArgumentException("NetUtils.decodePath: " +
"% character should be followed by 2 hexadecimal characters.");
}
}
try {
String translatedPart = new String(encodedchars, 0, encodedcharsLength, "UTF-8");
translatedPath.append(translatedPart);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Problem in decodePath: UTF-8 encoding not supported.");
}
encodedcharsLength = 0;
} else {
translatedPath.append(path.charAt(i));
i++;
}
}
return translatedPath.toString();
}
新建一个encodedchars数组,长度为路径长度的1/3,之后逐字读取路径,并记录。我们必须一次性处理所有连续的编码字符,因为它们代表UTF-8编码字符串,在UTF-8中,一个字符可以编码为多个字节。UTF-8不受支持的情况是非常理论化的,因此抛出一个运行时异常。
NullOutputStream:
1.方法:
void write(byte[] b)
void write(byte[] b, int off, int len)
void write(int b)
PostInputStream:
1.总结:
类PostInputStream是与POST消息关联的InputStream的包装器。它允许控制读取操作,将读取的字节数限制为getContentLen()方法返回的值。
2.方法:
int available()
返回此输入流中可用的字节数,该字节数可以在不阻塞流的情况下读取。
protected void checkOpen()
检查此流是否已关闭;如果是,则引发IOException。
void close()
通过关闭基础流并将其标记为关闭,关闭此输入流。
int getContentLen()
返回post消息正文长度。
InputStream getInputStream()
返回基础输入流。
protected void init(InputStream input, int len)
设置基础输入流和contentLen值。
boolean markSupported()
测试此输入流是否支持标记和重置方法。
int read()
从输入流读取下一个字节。
int read(byte[] buffer)
int read(byte[] buffer, int offset, int len)
从给定偏移量开始,将字节输入流中的字节读入指定的字节数组。
void setInputStream(InputStream input, int len)
设置基础输入流和contentLen值。
long skip(long n)
参见InputStream跳过方法的总合同。
String toString()
返回此的字符串表示形式。
ResizableContainer:
1.总结:
只可添加的容器类。
2.方法:
void add(Object o)
Object get(int index)
void set(int index, Object o)
int size()