优化命名
This commit is contained in:
@@ -17,7 +17,7 @@ import java.util.*;
|
||||
*/
|
||||
public class MimeType {
|
||||
|
||||
private final static Map<String, String> contentTypes = new HashMap<>();
|
||||
private static final Map<String, String> contentTypes = new HashMap<>();
|
||||
|
||||
static {
|
||||
contentTypes.put("abs", "audio/x-mpeg");
|
||||
@@ -177,6 +177,9 @@ public class MimeType {
|
||||
contentTypes.put("zip", "application/zip");
|
||||
}
|
||||
|
||||
private MimeType() {
|
||||
}
|
||||
|
||||
public static String get(String extension) {
|
||||
return contentTypes.getOrDefault(extension.toLowerCase(), "text/plain");
|
||||
}
|
||||
@@ -198,7 +201,9 @@ public class MimeType {
|
||||
public static String getByFilename(String fileName) {
|
||||
int length = fileName.length();
|
||||
int newEnd = fileName.lastIndexOf('#');
|
||||
if (newEnd == -1) newEnd = length;
|
||||
if (newEnd == -1) {
|
||||
newEnd = length;
|
||||
}
|
||||
int i = fileName.lastIndexOf('.', newEnd);
|
||||
return (i < 0) ? null : get(fileName.substring(i + 1, newEnd).toLowerCase());
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public final class MultiContext {
|
||||
continue;//不遍历完后面getParameter可能获取不到值
|
||||
}
|
||||
has = true;
|
||||
if (fileNameRegx != null && !fileNameRegx.isEmpty() && !part.getFilename().matches(fileNameRegx)) {
|
||||
if (fileNameRegx != null && !fileNameRegx.isEmpty() && !part.getFileName().matches(fileNameRegx)) {
|
||||
continue;
|
||||
}
|
||||
if (contentTypeRegx != null && !contentTypeRegx.isEmpty() && !part.getContentType().matches(contentTypeRegx)) {
|
||||
@@ -157,13 +157,13 @@ public final class MultiContext {
|
||||
continue; //不遍历完后面getParameter可能获取不到值
|
||||
}
|
||||
has = true;
|
||||
if (fileNameRegx != null && !fileNameRegx.isEmpty() && !part.getFilename().matches(fileNameRegx)) {
|
||||
if (fileNameRegx != null && !fileNameRegx.isEmpty() && !part.getFileName().matches(fileNameRegx)) {
|
||||
continue;
|
||||
}
|
||||
if (contentTypeRegx != null && !contentTypeRegx.isEmpty() && !part.getContentType().matches(contentTypeRegx)) {
|
||||
continue;
|
||||
}
|
||||
File file = new File(home, "tmp/redkale-" + System.nanoTime() + "_" + part.getFilename());
|
||||
File file = new File(home, "tmp/redkale-" + System.nanoTime() + "_" + part.getFileName());
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.isDirectory()) {
|
||||
parent.mkdirs();
|
||||
@@ -197,13 +197,13 @@ public final class MultiContext {
|
||||
}
|
||||
List<File> files = null;
|
||||
for (MultiPart part : parts()) {
|
||||
if (fileNameRegx != null && !fileNameRegx.isEmpty() && !part.getFilename().matches(fileNameRegx)) {
|
||||
if (fileNameRegx != null && !fileNameRegx.isEmpty() && !part.getFileName().matches(fileNameRegx)) {
|
||||
continue;
|
||||
}
|
||||
if (contentTypeRegx != null && !contentTypeRegx.isEmpty() && !part.getContentType().matches(contentTypeRegx)) {
|
||||
continue;
|
||||
}
|
||||
File file = new File(home, "tmp/redkale-" + System.nanoTime() + "_" + part.getFilename());
|
||||
File file = new File(home, "tmp/redkale-" + System.nanoTime() + "_" + part.getFileName());
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.isDirectory()) {
|
||||
parent.mkdirs();
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.concurrent.atomic.LongAdder;
|
||||
*/
|
||||
public final class MultiPart {
|
||||
|
||||
private final String filename;
|
||||
private final String fileName;
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class MultiPart {
|
||||
private final LongAdder received;
|
||||
|
||||
MultiPart(String fileName, String name, String contentType, LongAdder received, InputStream in) {
|
||||
this.filename = fileName;
|
||||
this.fileName = fileName;
|
||||
this.name = name;
|
||||
this.in = in;
|
||||
this.contentType = contentType;
|
||||
@@ -37,7 +37,7 @@ public final class MultiPart {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "{" + "name=" + name + ", filename=" + filename + ", contentType=" + contentType + ", received=" + received + '}';
|
||||
return this.getClass().getSimpleName() + "{" + "name=" + name + ", fileName=" + fileName + ", contentType=" + contentType + ", received=" + received + '}';
|
||||
}
|
||||
|
||||
public boolean save(File file) throws IOException {
|
||||
@@ -99,8 +99,19 @@ public final class MultiPart {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getFileName()
|
||||
*
|
||||
* @return String
|
||||
* @deprecated replace by {@link #getFileName() }
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
Reference in New Issue
Block a user