Skip to content

Commit

Permalink
Issue #797
Browse files Browse the repository at this point in the history
Use MimeTypes.class.getClassLoader to load properties.
  • Loading branch information
janbartel committed Aug 10, 2016
1 parent c1694ba commit a9653e2
Showing 1 changed file with 64 additions and 31 deletions.
95 changes: 64 additions & 31 deletions jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,50 +203,83 @@ public Type getBaseType()
}
}

String resourceName = "org/eclipse/jetty/http/mime";

try
String resourceName = "org/eclipse/jetty/http/mime.properties";
try (InputStream stream = MimeTypes.class.getClassLoader().getResourceAsStream(resourceName))
{
ResourceBundle mimeBundle = ResourceBundle.getBundle(resourceName);
mimeBundle.keySet().stream()
.filter(x->x!=null)
.forEach(x->
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(mimeBundle.getString(x))));

if (__dftMimeMap.size()==0)
if (stream == null)
{
LOG.warn("Empty mime types at {}", resourceName);
LOG.warn("Missing mime-type resource: {}", resourceName);
}
else if (__dftMimeMap.size()<mimeBundle.keySet().size())
else
{
LOG.warn("Duplicate or null mime-type extension in resource: {}", resourceName);
}
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8))
{
Properties props = new Properties();
props.load(reader);
props.stringPropertyNames().stream()
.filter(x->x!=null)
.forEach(x->
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(props.getProperty(x))));

if (__dftMimeMap.size()==0)
{
LOG.warn("Empty mime types at {}", resourceName);
}
else if (__dftMimeMap.size()<props.keySet().size())
{
LOG.warn("Duplicate or null mime-type extension in resource: {}", resourceName);
}
}
catch (IOException e)
{
LOG.warn(e.toString());
LOG.debug(e);
}

}
}
catch (MissingResourceException e)
catch (IOException e)
{
LOG.warn("Missing mime-type resource: {}", resourceName);
LOG.warn(e.toString());
LOG.debug(e);
}


resourceName = "org/eclipse/jetty/http/encoding";
try
resourceName = "org/eclipse/jetty/http/encoding.properties";
try (InputStream stream = MimeTypes.class.getClassLoader().getResourceAsStream(resourceName))
{
ResourceBundle encodingBundle = ResourceBundle.getBundle(resourceName);
encodingBundle.keySet().stream()
.filter(t->t!=null)
.forEach(t->__encodings.put(t, encodingBundle.getString(t)));

if (__encodings.size()==0)
if (stream == null)
LOG.warn("Missing encoding resource: {}", resourceName);
else
{
LOG.warn("Empty encodings at {}", resourceName);
}
else if (__encodings.size()<encodingBundle.keySet().size())
{
LOG.warn("Null or duplicate encodings in resource: {}", resourceName);
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8))
{
Properties props = new Properties();
props.load(reader);
props.stringPropertyNames().stream()
.filter(t->t!=null)
.forEach(t->__encodings.put(t, props.getProperty(t)));

if (__encodings.size()==0)
{
LOG.warn("Empty encodings at {}", resourceName);
}
else if (__encodings.size()<props.keySet().size())
{
LOG.warn("Null or duplicate encodings in resource: {}", resourceName);
}
}
catch (IOException e)
{
LOG.warn(e.toString());
LOG.debug(e);
}
}
}
catch (MissingResourceException e)
catch (IOException e)
{
LOG.warn("Missing encoding resource: {}", resourceName);
LOG.warn(e.toString());
LOG.debug(e);
}
}

Expand Down

0 comments on commit a9653e2

Please sign in to comment.