Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #5 from wangzijian/master

Remove deprecated files
  • Loading branch information...
commit 5f3c407988453c48a39882a4d64de5ea829e88a2 2 parents dd7ab8d + 4451106
@wangzijian wangzijian authored
View
2  README.md
@@ -133,7 +133,6 @@ storage.bucket("mybucket").object("data/upload/pic.jpg").entity(new File("d:\\us
自定义Metadata
```java
storage.bucket("mybucket").object("data/upload/mydata").
- reducedRedundancy().
contentType("application/octet-stream").
contentMD5("ABCDEFGUVWXYZ").
contentLanguage("en").
@@ -178,7 +177,6 @@ SNDAObjectMetadata metadata = storage.bucket("mybucket").object("music/norther.m
更新Object信息与Metadata
```java
storage.bucket("mybucket").object("music/norther.mp3").
- reducedRedundancy().
contentType("audio/mpeg").
metadata("x-snda-meta-nation", "Finland").
update();
View
BIN  deprecated_docs/GrandCloud_Java_SDK_develop_guide.doc
Binary file not shown
View
BIN  deprecated_docs/GrandCloud_Java_SDK_develop_guide.pdf
Binary file not shown
View
BIN  deprecated_docs/GrandCloud_Java_SDK_manual.doc
Binary file not shown
View
BIN  deprecated_docs/GrandCloud_Java_SDK_manual.pdf
Binary file not shown
View
97 src/main/java/com/snda/storage/core/MIMETypes.java
@@ -0,0 +1,97 @@
+package com.snda.storage.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import com.google.common.io.CharStreams;
+import com.google.common.io.InputSupplier;
+
+/**
+ *
+ * @author wangzijian@snda.com
+ *
+ */
+public class MIMETypes {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MIMETypes.class);
+
+ private static final String DEFAULT_MIMETYPE = "application/octet-stream";
+
+ private final Map<String, String> map;
+
+ private static class SingletonHolder {
+ static MIMETypes instance = new MIMETypes();
+ }
+
+ private MIMETypes() {
+ LOGGER.info("Loading mime types from file in the classpath: mime.types");
+ try {
+ map = loadMimetypes("/mime.types");
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to load mime types from file in the classpath: mime.types", e);
+ }
+ }
+
+ public static MIMETypes getInstance() {
+ return SingletonHolder.instance;
+ }
+
+ private static Map<String, String> loadMimetypes(String resource) throws IOException {
+ Map<String, String> map = Maps.newHashMap();
+ for (String line : readLines(resource)) {
+ line = line.trim();
+ if (line.startsWith("#") || line.length() == 0) {
+ continue;
+ } else {
+ StringTokenizer st = new StringTokenizer(line, " \t");
+ if (st.countTokens() > 1) {
+ String mimetype = st.nextToken();
+ while (st.hasMoreTokens()) {
+ String extension = st.nextToken();
+ map.put(extension, mimetype);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("Setting mime type for extension '" + extension + "' to '" + mimetype + "'");
+ }
+ }
+ }
+ }
+ }
+ return ImmutableMap.copyOf(map);
+ }
+
+ private static List<String> readLines(final String resource) throws IOException {
+ return CharStreams.readLines(new InputSupplier<Reader>() {
+ @Override
+ public Reader getInput() throws IOException {
+ return new InputStreamReader(MIMETypes.class.getResourceAsStream(resource));
+ }
+ });
+ }
+
+ public String getMimetype(String fileName) {
+ int lastPeriod = fileName.lastIndexOf(".");
+ if (lastPeriod > 0 && lastPeriod + 1 < fileName.length()) {
+ String extension = fileName.substring(lastPeriod + 1);
+ String mimetype = map.get(extension);
+ if (mimetype != null) {
+ LOGGER.info("Extension: '{}', mimetype: '{}'", extension, mimetype);
+ return mimetype;
+ }
+ }
+ return DEFAULT_MIMETYPE;
+ }
+
+ public String getMimetype(File file) {
+ return getMimetype(file.getName());
+ }
+}
View
2  src/main/java/com/snda/storage/core/UploadObjectRequest.java
@@ -61,7 +61,7 @@ public void setEntity(Entity entity) {
}
private String getContentType(File file) {
- return Mimetypes.getInstance().getMimetype(file);
+ return MIMETypes.getInstance().getMimetype(file);
}
private String getContentDisposition(File file) {
View
26 src/test/java/com/snda/storage/core/MIMETypesTest.java
@@ -0,0 +1,26 @@
+package com.snda.storage.core;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+/**
+ *
+ * @author wangzijian@snda.com
+ *
+ */
+public class MIMETypesTest {
+
+ @Test
+ public void testGetMimetype() {
+ assertEquals("text/plain", MIMETypes.getInstance().getMimetype("a.txt"));
+ assertEquals("application/pdf", MIMETypes.getInstance().getMimetype("a.pdf"));
+ assertEquals("application/octet-stream", MIMETypes.getInstance().getMimetype("a.exe"));
+ assertEquals("application/zip", MIMETypes.getInstance().getMimetype("a.zip"));
+ assertEquals("application/x-gzip", MIMETypes.getInstance().getMimetype("a.gz"));
+ assertEquals("audio/mpeg", MIMETypes.getInstance().getMimetype("a.mp3"));
+ assertEquals("video/mp4", MIMETypes.getInstance().getMimetype("a.mp4"));
+ assertEquals("application/msword", MIMETypes.getInstance().getMimetype("a.doc"));
+ assertEquals("application/vnd.ms-powerpoint", MIMETypes.getInstance().getMimetype("a.ppt"));
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.