Created
May 12, 2017 17:11
-
-
Save spyhunter99/9a4a802139011f2fc6eddc1829815b7c to your computer and use it in GitHub Desktop.
Using java, generates Java constants for all HTTP mime types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileInputStream; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
public class MimeGenerator { | |
public static void main(String[] args) throws Exception { | |
URL url = new URL("https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types"); | |
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); | |
String line = null; | |
int lineNumber=0; | |
while ((line = in.readLine()) != null) { | |
lineNumber++; | |
if (lineNumber > 15){ | |
//skip the headers | |
line = line.trim(); | |
if (line.startsWith("#")) | |
line = line.substring(1).trim(); | |
if (line.contains("\t")) { | |
//with an extension | |
line = line.substring(0, line.indexOf("\t")); | |
} | |
System.out.println("public static String " + safeName(line) + " = \"" + line + "\";"); | |
} | |
} | |
} | |
private static String safeName(String line) { | |
String text = line.toUpperCase(); | |
return text.replace("/", "_").replace("-", "_DASH_").replace("+", "_PLUS_").replace(".", "_DOT_"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment