Skip to content

Commit

Permalink
Bump version. Improve MediaType.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Aug 14, 2019
1 parent b243c60 commit b6ca5ec
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proteus-project</artifactId>
<groupId>io.sinistral</groupId>
<version>0.4.1</version>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
36 changes: 33 additions & 3 deletions core/src/main/java/io/sinistral/proteus/server/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/


import com.fasterxml.jackson.annotation.JsonProperty;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -966,6 +968,7 @@ public class MediaType
public static final MediaType IMAGE_GIF = create("image/gif", "gif");
public static final MediaType IMAGE_IEF = create("image/ief", "ief");
public static final MediaType IMAGE_JPEG = create("image/jpeg", "jpeg", "jpg", "jpe");
public static final MediaType IMAGE_JBIG = create("image/jbig", "jbig", "jbg");
public static final MediaType IMAGE_KTX = create("image/ktx", "ktx");
public static final MediaType IMAGE_PCX = create("image/pcx", "pcx");
public static final MediaType IMAGE_PNG = create("image/png", "png");
Expand Down Expand Up @@ -1230,11 +1233,11 @@ public static MediaType of(String contentType)
return new MediaType(contentType);
}


private final byte[] bytes;

private final String contentType;


private MediaType(String contentType)
{
this.bytes = contentType.getBytes();
Expand All @@ -1245,7 +1248,6 @@ private MediaType(String name, String[] attributes)
{
this.bytes = join(name, attributes).getBytes();
this.contentType = new String(this.bytes);

}

private String join(String name, String[] attributes)
Expand All @@ -1261,6 +1263,7 @@ public byte[] getBytes()
return bytes;
}

@JsonProperty("contentType")
public String contentType()
{
return this.contentType;
Expand All @@ -1272,8 +1275,35 @@ public String toString()
return this.contentType;
}

public String getFileExtension()
{
return Optional.ofNullable(EXTENSION_MAP.get(this)).map( fe -> fe.get(0)).orElse(null);
}

public List<String> getFileExtensions()
{
return Optional.ofNullable(EXTENSION_MAP.get(this)).orElse(null);
}

public String subType()
{
return this.contentType.substring(this.contentType.lastIndexOf("/") + 1, Math.max(this.contentType.lastIndexOf(";"),this.contentType.length()));
}

private static final Map<String,MediaType> TYPE_MAP = new HashMap<>();

private static final Map<MediaType,List<String>> EXTENSION_MAP = new HashMap<>();

public static Map<MediaType,List<String>> getFileExtensionMap()
{
if(EXTENSION_MAP.size() == 0) {

EXTENSION_MAP.putAll(FILE_EXTENSIONS.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList()))));
}

return EXTENSION_MAP;
}

public static Map<String,MediaType> getTypeMap()
{
if(TYPE_MAP.size() == 0) {
Expand All @@ -1289,7 +1319,7 @@ public static Map<String,MediaType> getTypeMap()
TYPE_MAP.put(mt.contentType,mt);
} catch( Exception e )
{
e.printStackTrace();

}
});
}
Expand Down
2 changes: 1 addition & 1 deletion openapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proteus-project</artifactId>
<groupId>io.sinistral</groupId>
<version>0.4.1</version>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.sinistral</groupId>
<artifactId>proteus-project</artifactId>
<packaging>pom</packaging>
<version>0.4.1</version>
<version>0.4.2-SNAPSHOT</version>

<description>Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.</description>
<url>http://github.com/noboomu/proteus</url>
Expand Down
2 changes: 1 addition & 1 deletion swagger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proteus-project</artifactId>
<groupId>io.sinistral</groupId>
<version>0.4.1</version>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit b6ca5ec

Please sign in to comment.