Permalink
Browse files

reformat code

  • Loading branch information...
1 parent da4137a commit ebd59b50edd4f477157cbc3d90aa6dd95ee73618 @dine909 committed Oct 2, 2011
Showing with 485 additions and 449 deletions.
  1. +5 −5 com/dinamoproductions/wowow/filesystem/AbstractFile.java
  2. +65 −56 com/dinamoproductions/wowow/filesystem/ClassResourceFile.java
  3. +2 −2 com/dinamoproductions/wowow/filesystem/FileSystemFile.java
  4. +4 −3 com/dinamoproductions/wowow/server/AbstractSocketHandle.java
  5. +4 −6 com/dinamoproductions/wowow/server/AbstractSocketHandler.java
  6. +43 −36 com/dinamoproductions/wowow/server/Server.java
  7. +7 −7 com/dinamoproductions/wowow/server/http/AbstractHttpHandler.java
  8. +16 −14 com/dinamoproductions/wowow/server/http/DefaultHttpHandler.java
  9. +27 −26 com/dinamoproductions/wowow/server/http/HttpCacheControl.java
  10. +55 −60 com/dinamoproductions/wowow/server/http/HttpDate.java
  11. +3 −2 com/dinamoproductions/wowow/server/http/HttpHeaderMatcher.java
  12. +1 −2 com/dinamoproductions/wowow/server/http/HttpHeaders.java
  13. +20 −16 com/dinamoproductions/wowow/server/http/HttpRequest.java
  14. +36 −30 com/dinamoproductions/wowow/server/http/HttpResponse.java
  15. +3 −3 com/dinamoproductions/wowow/server/http/HttpSocketHandle.java
  16. +6 −6 com/dinamoproductions/wowow/server/http/HttpSocketHandler.java
  17. +7 −7 com/dinamoproductions/wowow/server/http/MimeTypes.java
  18. +28 −23 com/dinamoproductions/wowow/server/http/PathMatcher.java
  19. +47 −47 com/dinamoproductions/wowow/server/http/StatusCodes.java
  20. +103 −95 com/dinamoproductions/wowow/server/http/handlers/FileSystemHttpHandler.java
  21. +3 −3 com/dinamoproductions/wowow/server/utils.java
View
10 com/dinamoproductions/wowow/filesystem/AbstractFile.java
@@ -5,11 +5,10 @@
public abstract class AbstractFile extends File {
-
- public InputStream openInputStream() throws FileNotFoundException{
+ public InputStream openInputStream() throws FileNotFoundException {
return null;
}
-
+
public AbstractFile(String pathname) {
super(pathname);
// TODO Auto-generated constructor stub
@@ -29,8 +28,9 @@ public AbstractFile(File parent, String child) {
super(parent, child);
// TODO Auto-generated constructor stub
}
- public AbstractFile getFile(String path){
+
+ public AbstractFile getFile(String path) {
return null;
-
+
}
}
View
121 com/dinamoproductions/wowow/filesystem/ClassResourceFile.java
@@ -6,43 +6,45 @@
import java.util.jar.*;
public class ClassResourceFile extends AbstractFile {
- public Class<? extends Object> resourceClass=null;
-
- public InputStream openInputStream() throws FileNotFoundException{
+ public Class<? extends Object> resourceClass = null;
+
+ public InputStream openInputStream() throws FileNotFoundException {
String path = removeSlash();
return resourceClass.getResourceAsStream(path);
}
private String removeSlash() {
String path = this.getPath();
-// if(path.startsWith("/")){
-// path=path.substring(1);
-//
-// }
+ // if(path.startsWith("/")){
+ // path=path.substring(1);
+ //
+ // }
return path;
}
-
- public AbstractFile getFile(){
+
+ public AbstractFile getFile() {
String path = removeSlash();
URL dirURL = resourceClass.getClassLoader().getResource(path);
if (dirURL != null && dirURL.getProtocol().equals("file")) {
String parts = resourceClass.toString().split(" ")[1];
- int lastdot=parts.lastIndexOf('.');
- String classdir=parts.substring(0, lastdot).replace('.', '/');
-
- return new FileSystemFile(dirURL.toString().substring(5)+classdir);
- }
+ int lastdot = parts.lastIndexOf('.');
+ String classdir = parts.substring(0, lastdot).replace('.', '/');
+
+ return new FileSystemFile(dirURL.toString().substring(5) + classdir);
+ }
return this;
}
-
+
public ClassResourceFile(String pathname) throws IOException {
super(pathname);
throw new IOException("Cannot create ClassResourceFile with no clazz");
// TODO Auto-generated constructor stub
}
- public ClassResourceFile(Class<? extends Object> clazz, String pathname) throws IOException {
+
+ public ClassResourceFile(Class<? extends Object> clazz, String pathname)
+ throws IOException {
super(pathname);
- resourceClass=clazz;
+ resourceClass = clazz;
// TODO Auto-generated constructor stub
}
@@ -58,7 +60,7 @@ public ClassResourceFile(String parent, String child) {
public ClassResourceFile(File parent, String child) {
super(parent, child);
- resourceClass=((ClassResourceFile)parent).resourceClass;
+ resourceClass = ((ClassResourceFile) parent).resourceClass;
// TODO Auto-generated constructor stub
}
@@ -73,16 +75,16 @@ public boolean isDirectory() {
// TODO Auto-generated method stub
String path = removeSlash();
URL dirURL = resourceClass.getClassLoader().getResource(path);
- if (dirURL != null && dirURL.getProtocol().equals("file")) {
- /* A file path: easy enough */
- try {
+ if (dirURL != null && dirURL.getProtocol().equals("file")) {
+ /* A file path: easy enough */
+ try {
return new File(dirURL.toURI()).isDirectory();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- }
- return false;
+ }
+ return false;
}
@Override
@@ -103,21 +105,23 @@ public boolean isFile() {
// TODO Auto-generated catch block
e.printStackTrace();
}
- }
-
- if (dirURL == null) {
- /*
- * In case of a jar file, we can't actually find a directory.
- * Have to assume the same jar as clazz.
- */
- String me = resourceClass.getName().replace(".", "/")+".class";
- dirURL = resourceClass.getClassLoader().getResource(me);
- }
-
- if (dirURL.getProtocol().equals("jar")) {
- /* A JAR path */
- String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file
- JarFile jar = null;
+ }
+
+ if (dirURL == null) {
+ /*
+ * In case of a jar file, we can't actually find a directory. Have
+ * to assume the same jar as clazz.
+ */
+ String me = resourceClass.getName().replace(".", "/") + ".class";
+ dirURL = resourceClass.getClassLoader().getResource(me);
+ }
+
+ if (dirURL.getProtocol().equals("jar")) {
+ /* A JAR path */
+ String jarPath = dirURL.getPath().substring(5,
+ dirURL.getPath().indexOf("!")); // strip out only the JAR
+ // file
+ JarFile jar = null;
try {
jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
} catch (UnsupportedEncodingException e) {
@@ -127,24 +131,29 @@ public boolean isFile() {
// TODO Auto-generated catch block
e.printStackTrace();
}
- Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
- Set<String> result = new HashSet<String>(); //avoid duplicates in case it is a subdirectory
- while(entries.hasMoreElements()) {
- String name = entries.nextElement().getName();
- if (name.startsWith(path)) { //filter according to the path
- String entry = name.substring(path.length());
- int checkSubdir = entry.indexOf("/");
- if (checkSubdir >= 0) {
- // if it is a subdirectory, we just return the directory name
- entry = entry.substring(0, checkSubdir);
- }
- result.add(entry);
- }
- }
- return result.toArray(new String[result.size()]);
- }
-
- throw new UnsupportedOperationException("Cannot list files for URL "+dirURL);
+ Enumeration<JarEntry> entries = jar.entries(); // gives ALL entries
+ // in jar
+ Set<String> result = new HashSet<String>(); // avoid duplicates in
+ // case it is a
+ // subdirectory
+ while (entries.hasMoreElements()) {
+ String name = entries.nextElement().getName();
+ if (name.startsWith(path)) { // filter according to the path
+ String entry = name.substring(path.length());
+ int checkSubdir = entry.indexOf("/");
+ if (checkSubdir >= 0) {
+ // if it is a subdirectory, we just return the directory
+ // name
+ entry = entry.substring(0, checkSubdir);
+ }
+ result.add(entry);
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
+ throw new UnsupportedOperationException("Cannot list files for URL "
+ + dirURL);
}
}
View
4 com/dinamoproductions/wowow/filesystem/FileSystemFile.java
@@ -5,7 +5,7 @@
public class FileSystemFile extends AbstractFile {
- public InputStream openInputStream() throws FileNotFoundException{
+ public InputStream openInputStream() throws FileNotFoundException {
return new FileInputStream(this.getAbsolutePath());
}
@@ -32,7 +32,7 @@ public FileSystemFile(File parent, String child) {
@Override
public AbstractFile getFile(String path) {
// TODO Auto-generated method stub
- return new FileSystemFile(this,path);
+ return new FileSystemFile(this, path);
}
}
View
7 com/dinamoproductions/wowow/server/AbstractSocketHandle.java
@@ -4,13 +4,14 @@
import java.net.*;
public abstract class AbstractSocketHandle extends Thread {
- public Socket baseSocket=null;
+ public Socket baseSocket = null;
+
public AbstractSocketHandle(Socket s) {
- baseSocket=s;
+ baseSocket = s;
}
@Override
- public void run(){
+ public void run() {
try {
baseSocket.close();
} catch (IOException e) {
View
10 com/dinamoproductions/wowow/server/AbstractSocketHandler.java
@@ -2,12 +2,10 @@
import java.net.*;
-public abstract class AbstractSocketHandler {
-
- public void handle(Socket _s){
-
- }
+public abstract class AbstractSocketHandler {
+
+ public void handle(Socket _s) {
+ }
-
}
View
79 com/dinamoproductions/wowow/server/Server.java
@@ -13,20 +13,21 @@
public class Server extends Thread {
public static LinkedList<Socket> clientList = new LinkedList<Socket>();
- boolean running=false;
- ServerSocket listener=null;
+ boolean running = false;
+ ServerSocket listener = null;
AbstractSocketHandler shSocketHandler;
-
+
public Server(int port) throws IOException {
super();
-
+
InetAddress ipadr = InetAddress.getByName("0.0.0.0");
- listener = new ServerSocket(port,0,ipadr);
- running=true;
+ listener = new ServerSocket(port, 0, ipadr);
+ running = true;
}
+
@Override
public void run() {
- while( running ) {
+ while (running) {
Socket client = null;
try {
client = listener.accept();
@@ -38,9 +39,11 @@ public void run() {
clientList.add(client);
}
}
- public void setSocketHandler(AbstractSocketHandler _cS){
- shSocketHandler=_cS;
+
+ public void setSocketHandler(AbstractSocketHandler _cS) {
+ shSocketHandler = _cS;
}
+
public void stopServer() {
running = false;
try {
@@ -49,42 +52,46 @@ public void stopServer() {
e.printStackTrace();
}
}
+
public synchronized static void remove(Socket s) {
- clientList.remove(s);
- }
- public static void main(String [ ] args) throws IOException, InterruptedException
- {
- int port=8888;
- String dir="/";
- if(args!=null){
- if(args.length>0)
- {
- dir=args[0];
+ clientList.remove(s);
+ }
+
+ public static void main(String[] args) throws IOException,
+ InterruptedException {
+ int port = 8888;
+ String dir = "/";
+ if (args != null) {
+ if (args.length > 0) {
+ dir = args[0];
}
- if(args.length>1)
- {
- port=Integer.parseInt(args[1], 10);
+ if (args.length > 1) {
+ port = Integer.parseInt(args[1], 10);
}
}
- Server s= new Server(port);
- HttpSocketHandler httpSocketHandler=new HttpSocketHandler();
-
- //serve files
+ Server s = new Server(port);
+ HttpSocketHandler httpSocketHandler = new HttpSocketHandler();
+
+ // serve files
FileSystemHttpHandler fileSystemHandler = new FileSystemHttpHandler(
- (HttpHeaderMatcher) new PathMatcher("/files/*"),new FileSystemFile(dir));
- fileSystemHandler.allowDirectoryBrowsing=true;
+ (HttpHeaderMatcher) new PathMatcher("/files/*"),
+ new FileSystemFile(dir));
+ fileSystemHandler.allowDirectoryBrowsing = true;
httpSocketHandler.addHandler(fileSystemHandler);
- //serve resources
- AbstractFile classResourceFile = new ClassResourceFile(ClassResourceFile.class,"").getFile();
+ // serve resources
+ AbstractFile classResourceFile = new ClassResourceFile(
+ ClassResourceFile.class, "").getFile();
FileSystemHttpHandler fileSystemHandler1 = new FileSystemHttpHandler(
- (HttpHeaderMatcher) new PathMatcher("/res/*"),classResourceFile);
- fileSystemHandler1.allowDirectoryBrowsing=true;
+ (HttpHeaderMatcher) new PathMatcher("/res/*"),
+ classResourceFile);
+ fileSystemHandler1.allowDirectoryBrowsing = true;
httpSocketHandler.addHandler(fileSystemHandler1);
-
- //serve errors
- httpSocketHandler.addHandler(new DefaultHttpHandler((HttpHeaderMatcher) new PathMatcher("/*")));
-
+
+ // serve errors
+ httpSocketHandler.addHandler(new DefaultHttpHandler(
+ (HttpHeaderMatcher) new PathMatcher("/*")));
+
s.setSocketHandler(httpSocketHandler);
s.start();
s.join();
View
14 com/dinamoproductions/wowow/server/http/AbstractHttpHandler.java
@@ -5,18 +5,18 @@
import java.net.Socket;
import java.net.URISyntaxException;
-
public abstract class AbstractHttpHandler {
- public HttpHeaderMatcher httpHeaderMatcher=null;
+ public HttpHeaderMatcher httpHeaderMatcher = null;
public AbstractHttpHandler(HttpHeaderMatcher m) {
- httpHeaderMatcher=m;
+ httpHeaderMatcher = m;
}
- public void handle(HttpRequest request) throws IOException, URISyntaxException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
-
- }
+ public void handle(HttpRequest request) throws IOException,
+ URISyntaxException, SecurityException, NoSuchMethodException,
+ IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException, InstantiationException {
+ }
-
}
View
30 com/dinamoproductions/wowow/server/http/DefaultHttpHandler.java
@@ -4,26 +4,28 @@
import java.net.Socket;
import java.net.URISyntaxException;
+public class DefaultHttpHandler extends AbstractHttpHandler {
-public class DefaultHttpHandler extends AbstractHttpHandler{
-
public DefaultHttpHandler(HttpHeaderMatcher matcher) {
super(matcher);
-
+
}
- public void handle(HttpRequest request) throws IOException, URISyntaxException {
- if(!this.httpHeaderMatcher.matchHeader(request)) return;
- HttpResponse response=null;
- response=request.getResponse();
- String sres=response.statusCode;
- BufferedInputStream is = new BufferedInputStream(new ByteArrayInputStream(sres.getBytes()));
-
-// response.statusCode=StatusCodes.SC_OK;
+ public void handle(HttpRequest request) throws IOException,
+ URISyntaxException {
+ if (!this.httpHeaderMatcher.matchHeader(request))
+ return;
+ HttpResponse response = null;
+ response = request.getResponse();
+ String sres = response.statusCode;
+ BufferedInputStream is = new BufferedInputStream(
+ new ByteArrayInputStream(sres.getBytes()));
+
+ // response.statusCode=StatusCodes.SC_OK;
response.setHeader("Content-Type", "text/plain; charset=iso-8859-1");
- response.inputStream=is;
- request.handled=true;
-
+ response.inputStream = is;
+ request.handled = true;
+
}
}
View
53 com/dinamoproductions/wowow/server/http/HttpCacheControl.java
@@ -4,36 +4,37 @@
import java.util.Date;
public class HttpCacheControl {
- String cacheControl=null;
- String sImsDate=null;
- boolean mustNotCache=false;
- public boolean preferCache=false;
- boolean onlyCache=false;
- public boolean ifNotModified=false;
-
- public HttpCacheControl(HttpRequest request) throws IOException{
- cacheControl=request.getHeader("cache-control:");
- sImsDate=request.getHeader("if-modified-since:");
-
- if(cacheControl!=null){
- if(cacheControl.contains("max-age=0")||cacheControl.contains("no-cache")){
- mustNotCache=true;
- preferCache=false;
+ String cacheControl = null;
+ String sImsDate = null;
+ boolean mustNotCache = false;
+ public boolean preferCache = false;
+ boolean onlyCache = false;
+ public boolean ifNotModified = false;
+
+ public HttpCacheControl(HttpRequest request) throws IOException {
+ cacheControl = request.getHeader("cache-control:");
+ sImsDate = request.getHeader("if-modified-since:");
+
+ if (cacheControl != null) {
+ if (cacheControl.contains("max-age=0")
+ || cacheControl.contains("no-cache")) {
+ mustNotCache = true;
+ preferCache = false;
}
- if(cacheControl.contains("only-if-cached")){
- preferCache=true;
- mustNotCache=false;
- onlyCache=true;
+ if (cacheControl.contains("only-if-cached")) {
+ preferCache = true;
+ mustNotCache = false;
+ onlyCache = true;
}
}
- if(sImsDate!=null){
- HttpResponse response=request.getResponse();
-
- if(sImsDate.equals(response.getHeader("Last-Modified:"))){
- response.statusCode=StatusCodes.SC_NOT_MODIFIED;
- ifNotModified=true;
+ if (sImsDate != null) {
+ HttpResponse response = request.getResponse();
+
+ if (sImsDate.equals(response.getHeader("Last-Modified:"))) {
+ response.statusCode = StatusCodes.SC_NOT_MODIFIED;
+ ifNotModified = true;
}
}
- onlyCache=onlyCache;
+ onlyCache = onlyCache;
}
}
View
115 com/dinamoproductions/wowow/server/http/HttpDate.java
@@ -5,67 +5,62 @@
import java.util.Locale;
import java.util.TimeZone;
-
public class HttpDate {
- /**
- * US locale - all HTTP dates are in english
- */
- public final static Locale LOCALE_US = Locale.US;
-
- /**
- * GMT timezone - all HTTP dates are on GMT
- */
- public final static TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
-
- /**
- * format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
- */
- public final static String RFC1123_PATTERN =
- "EEE, dd MMM yyyy HH:mm:ss z";
-
- /**
- * Format for http response header date field
- */
- public static final String HTTP_RESPONSE_DATE_HEADER =
- "EEE, dd MMM yyyy HH:mm:ss zzz";
-
- // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
- private final static String rfc1036Pattern =
- "EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
-
- // format for C asctime() date string -- "Sun Nov 6 08:49:37 1994"
- private final static String asctimePattern =
- "EEE MMM d HH:mm:ss yyyy";
-
- /**
- * Pattern used for old cookies
- */
- public final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
-
- /**
- * DateFormat to be used to format dates
- */
- public final static DateFormat rfc1123Format =
- new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
-
- /**
- * DateFormat to be used to format old netscape cookies
- */
- public final static DateFormat oldCookieFormat =
- new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
-
- public final static DateFormat rfc1036Format =
- new SimpleDateFormat(rfc1036Pattern, LOCALE_US);
-
- public final static DateFormat asctimeFormat =
- new SimpleDateFormat(asctimePattern, LOCALE_US);
-
- static {
- rfc1123Format.setTimeZone(GMT_ZONE);
- oldCookieFormat.setTimeZone(GMT_ZONE);
- rfc1036Format.setTimeZone(GMT_ZONE);
- asctimeFormat.setTimeZone(GMT_ZONE);
- }
+ /**
+ * US locale - all HTTP dates are in english
+ */
+ public final static Locale LOCALE_US = Locale.US;
+
+ /**
+ * GMT timezone - all HTTP dates are on GMT
+ */
+ public final static TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
+
+ /**
+ * format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
+ */
+ public final static String RFC1123_PATTERN = "EEE, dd MMM yyyy HH:mm:ss z";
+
+ /**
+ * Format for http response header date field
+ */
+ public static final String HTTP_RESPONSE_DATE_HEADER = "EEE, dd MMM yyyy HH:mm:ss zzz";
+
+ // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
+ private final static String rfc1036Pattern = "EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
+
+ // format for C asctime() date string -- "Sun Nov 6 08:49:37 1994"
+ private final static String asctimePattern = "EEE MMM d HH:mm:ss yyyy";
+
+ /**
+ * Pattern used for old cookies
+ */
+ public final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
+
+ /**
+ * DateFormat to be used to format dates
+ */
+ public final static DateFormat rfc1123Format = new SimpleDateFormat(
+ RFC1123_PATTERN, LOCALE_US);
+
+ /**
+ * DateFormat to be used to format old netscape cookies
+ */
+ public final static DateFormat oldCookieFormat = new SimpleDateFormat(
+ OLD_COOKIE_PATTERN, LOCALE_US);
+
+ public final static DateFormat rfc1036Format = new SimpleDateFormat(
+ rfc1036Pattern, LOCALE_US);
+
+ public final static DateFormat asctimeFormat = new SimpleDateFormat(
+ asctimePattern, LOCALE_US);
+
+ static {
+ rfc1123Format.setTimeZone(GMT_ZONE);
+ oldCookieFormat.setTimeZone(GMT_ZONE);
+ rfc1036Format.setTimeZone(GMT_ZONE);
+ asctimeFormat.setTimeZone(GMT_ZONE);
+ }
}
View
5 com/dinamoproductions/wowow/server/http/HttpHeaderMatcher.java
@@ -4,8 +4,9 @@
import java.net.URISyntaxException;
public class HttpHeaderMatcher {
-
- public boolean matchHeader(HttpRequest request) throws IOException, URISyntaxException{
+
+ public boolean matchHeader(HttpRequest request) throws IOException,
+ URISyntaxException {
return true;
}
}
View
3 com/dinamoproductions/wowow/server/http/HttpHeaders.java
@@ -3,7 +3,6 @@
import java.util.Hashtable;
import java.util.LinkedList;
-public class HttpHeaders extends Hashtable{
+public class HttpHeaders extends Hashtable {
-
}
View
36 com/dinamoproductions/wowow/server/http/HttpRequest.java
@@ -13,9 +13,9 @@
private URI relPath = null;
HttpResponse httpResponse = null;
private HttpHeaders headers = new HttpHeaders();
- boolean gotAllHeaders=false;
+ boolean gotAllHeaders = false;
BufferedReader in = null;
- private HttpCacheControl httpCacheControl=null;
+ private HttpCacheControl httpCacheControl = null;
public HttpRequest(Socket s) {
baseSocket = s;
@@ -27,21 +27,22 @@ public HttpCacheControl getHttpCacheControl() throws IOException {
}
return httpCacheControl;
}
-
+
public HttpResponse getResponse() throws IOException {
if (httpResponse == null) {
return httpResponse = new HttpResponse();
}
return httpResponse;
}
- public URI getPathInfo() throws IOException, URISyntaxException{
- if(pathInfo==null){
- String get=getHeader("get").split(" ")[0];
- pathInfo=new URI(get).normalize();
+
+ public URI getPathInfo() throws IOException, URISyntaxException {
+ if (pathInfo == null) {
+ String get = getHeader("get").split(" ")[0];
+ pathInfo = new URI(get).normalize();
}
return pathInfo;
}
-
+
public HttpHeaders getHeaders(String header) throws IOException {
if (header != null)
header = header.toLowerCase();
@@ -56,7 +57,7 @@ public HttpHeaders getHeaders(String header) throws IOException {
s = in.readLine().trim();
if (s.equals("")) {
- gotAllHeaders=true;
+ gotAllHeaders = true;
break;
}
Pattern pattern = Pattern.compile("^(.*?) (.*)$");
@@ -79,7 +80,8 @@ public HttpHeaders getHeaders(String header) throws IOException {
}
private BufferedReader getInputStream() throws IOException {
- if(in!=null)return in;
+ if (in != null)
+ return in;
in = new BufferedReader(new InputStreamReader(
baseSocket.getInputStream()));
return in;
@@ -88,9 +90,10 @@ private BufferedReader getInputStream() throws IOException {
public String getHeader(String header) {
String h = null;
try {
- header=header.toLowerCase();
- h= (String) headers.get(header);
- if(h!=null)return h;
+ header = header.toLowerCase();
+ h = (String) headers.get(header);
+ if (h != null)
+ return h;
h = (String) this.getHeaders(header).get(header);
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -101,11 +104,12 @@ public String getHeader(String header) {
}
public void setPath(URI substring) {
- relPath=substring;
-
+ relPath = substring;
+
}
+
public URI getPath() {
return relPath;
-
+
}
}
View
66 com/dinamoproductions/wowow/server/http/HttpResponse.java
@@ -7,55 +7,62 @@
import com.dinamoproductions.wowow.server.utils.ChannelTools;
public class HttpResponse {
- public InputStream inputStream=null ;
- private HttpHeaders headers=new HttpHeaders();
- public String statusCode=StatusCodes.SC_NOT_FOUND;
+ public InputStream inputStream = null;
+ private HttpHeaders headers = new HttpHeaders();
+ public String statusCode = StatusCodes.SC_NOT_FOUND;
public String mimetype;
- protected String cacheControlMaxAge=null;
+ protected String cacheControlMaxAge = null;
+
public HttpResponse() {
setCacheMaxAge(0);
}
- public void setCacheMaxAge(int age){
- cacheControlMaxAge="max-age="+age;
- if(age==0) {
- cacheControlMaxAge+=" must-revalidate";
+
+ public void setCacheMaxAge(int age) {
+ cacheControlMaxAge = "max-age=" + age;
+ if (age == 0) {
+ cacheControlMaxAge += " must-revalidate";
}
}
- public void setHeader(String key,String value){
+
+ public void setHeader(String key, String value) {
headers.put(key, value);
}
- public String getHeader(String key){
+
+ public String getHeader(String key) {
return (String) headers.get(key);
}
-
- public String getHeaders(){
- String ret="";
+
+ public String getHeaders() {
+ String ret = "";
Enumeration e = headers.keys();
- while(e.hasMoreElements()){
- String k=(String) e.nextElement();
- String v=(String) headers.get(k);
- ret+=k+" "+v+"\n";
+ while (e.hasMoreElements()) {
+ String k = (String) e.nextElement();
+ String v = (String) headers.get(k);
+ ret += k + " " + v + "\n";
}
return ret;
-
+
}
- public void redirect(HttpRequest httpRequest, String location) throws IOException{
- statusCode=StatusCodes.SC_FOUND;
+ public void redirect(HttpRequest httpRequest, String location)
+ throws IOException {
+ statusCode = StatusCodes.SC_FOUND;
setHeader("Location:", location);
- httpRequest.handled=true;
+ httpRequest.handled = true;
}
+
protected void sendResponse(OutputStream ros) throws IOException {
-
+
setHeader("Server:", "com.dinamoproductions.wowow");
setHeader("Connection:", "close");
setHeader("Cache-Control:", cacheControlMaxAge);
setHeader("Date:", HttpDate.rfc1123Format.format(new Date()));
-
- if (inputStream != null&&getHeader("Content-Length:")==null)
- setHeader("Content-Length:", Integer.toString(inputStream.available(),10));
-
+
+ if (inputStream != null && getHeader("Content-Length:") == null)
+ setHeader("Content-Length:",
+ Integer.toString(inputStream.available(), 10));
+
String h = getHeaders();
BufferedOutputStream bos = new BufferedOutputStream(ros);
PrintWriter pw = new PrintWriter(bos, true);
@@ -67,8 +74,7 @@ protected void sendResponse(OutputStream ros) throws IOException {
if (inputStream != null) {
try {
- ChannelTools
- .streamCopy(inputStream, bos);
+ ChannelTools.streamCopy(inputStream, bos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -78,6 +84,7 @@ protected void sendResponse(OutputStream ros) throws IOException {
bos.flush();
bos.close();
}
+
public void sendErrorResponse(HttpRequest request, Exception e) {
String sres = statusCode;
@@ -90,8 +97,7 @@ public void sendErrorResponse(HttpRequest request, Exception e) {
new ByteArrayInputStream(sres.getBytes()));
statusCode = StatusCodes.SC_INTERNAL_SERVER_ERROR;
- setHeader("Content-Type",
- "text/plain; charset=iso-8859-1");
+ setHeader("Content-Type", "text/plain; charset=iso-8859-1");
inputStream = is;
request.handled = true;
}
View
6 com/dinamoproductions/wowow/server/http/HttpSocketHandle.java
@@ -19,9 +19,9 @@ public HttpSocketHandle(Socket _s, LinkedList<AbstractHttpHandler> h) {
public void run() {
HttpRequest request = new HttpRequest(this.baseSocket);
HttpResponse response = null;
- URI uNormalized =null;
- try {
- response=request.getResponse();
+ URI uNormalized = null;
+ try {
+ response = request.getResponse();
for (AbstractHttpHandler h : handlerList) {
h.handle(request);
if (request.handled)
View
12 com/dinamoproductions/wowow/server/http/HttpSocketHandler.java
@@ -6,21 +6,21 @@
import com.dinamoproductions.wowow.server.*;
import com.dinamoproductions.wowow.server.http.handlers.*;
-public class HttpSocketHandler extends AbstractSocketHandler {
+public class HttpSocketHandler extends AbstractSocketHandler {
public static LinkedList<AbstractHttpHandler> handlerList = new LinkedList<AbstractHttpHandler>();
public HttpSocketHandler() {
super();
// TODO Auto-generated constructor stub
}
-
- public void addHandler(AbstractHttpHandler h){
+
+ public void addHandler(AbstractHttpHandler h) {
handlerList.add(h);
}
-
+
@Override
- public void handle(Socket s){
- HttpSocketHandle hh=new HttpSocketHandle(s,handlerList);
+ public void handle(Socket s) {
+ HttpSocketHandle hh = new HttpSocketHandle(s, handlerList);
hh.start();
}
View
14 com/dinamoproductions/wowow/server/http/MimeTypes.java
@@ -3,12 +3,12 @@
import java.util.*;
public class MimeTypes {
- public static final Map<Integer, String> extentions = createMap();
+ public static final Map<Integer, String> extentions = createMap();
- private static Map<Integer, String> createMap() {
- Map<Integer, String> result = new HashMap<Integer, String>();
- result.put(1, "one");
- result.put(2, "two");
- return Collections.unmodifiableMap(result);
- }
+ private static Map<Integer, String> createMap() {
+ Map<Integer, String> result = new HashMap<Integer, String>();
+ result.put(1, "one");
+ result.put(2, "two");
+ return Collections.unmodifiableMap(result);
+ }
}
View
51 com/dinamoproductions/wowow/server/http/PathMatcher.java
@@ -6,41 +6,46 @@
import java.util.regex.*;
public class PathMatcher extends HttpHeaderMatcher {
- String path=null;
- private Pattern pMatcher=null;
- public String matched=null;
-
+ String path = null;
+ private Pattern pMatcher = null;
+ public String matched = null;
+
public PathMatcher(String p) {
- path=p;
+ path = p;
}
- private Pattern getMatcherPattern(HttpRequest request) throws IOException{
- if(pMatcher!=null) return pMatcher;
- String regex="";
- if(path.endsWith("/*")){
- String tamePath = path.substring(0,path.length()-2);
- regex="("+tamePath;
- regex+=")/.*";
- regex+="|"+tamePath;
- }else{
- regex="("+path+")";
+
+ private Pattern getMatcherPattern(HttpRequest request) throws IOException {
+ if (pMatcher != null)
+ return pMatcher;
+ String regex = "";
+ if (path.endsWith("/*")) {
+ String tamePath = path.substring(0, path.length() - 2);
+ regex = "(" + tamePath;
+ regex += ")/.*";
+ regex += "|" + tamePath;
+ } else {
+ regex = "(" + path + ")";
}
- return pMatcher=Pattern.compile(regex);
+ return pMatcher = Pattern.compile(regex);
}
+
@Override
- public boolean matchHeader(HttpRequest request) throws IOException, URISyntaxException{
+ public boolean matchHeader(HttpRequest request) throws IOException,
+ URISyntaxException {
URI pathInfo = request.getPathInfo();
String URIPath = pathInfo.getRawPath();
- Matcher matcher=getMatcherPattern(request).matcher(URIPath);
- boolean matches=matcher.matches();
+ Matcher matcher = getMatcherPattern(request).matcher(URIPath);
+ boolean matches = matcher.matches();
if (matches) {
- String mResult=matcher.group(1);
- if(mResult==null)mResult=matcher.group(0);
+ String mResult = matcher.group(1);
+ if (mResult == null)
+ mResult = matcher.group(0);
int matchEnd = mResult.length();
- matched = URIPath.substring(0,matchEnd);
+ matched = URIPath.substring(0, matchEnd);
request.setPath(new URI(URIPath.substring(matchEnd)));
}
return matches;
}
-
+
}
View
94 com/dinamoproductions/wowow/server/http/StatusCodes.java
@@ -1,52 +1,52 @@
package com.dinamoproductions.wowow.server.http;
public class StatusCodes {
- public static String SC_ACCEPTED ="202 Accepted";
- public static String SC_BAD_GATEWAY ="502 Bad Gateway";
- public static String SC_BAD_REQUEST ="400 Bad Request";
- public static String SC_CONFLICT ="409 Conflict";
- public static String SC_CONTINUE ="100 Continue";
- public static String SC_CREATED ="201 Created";
- public static String SC_EXPECTATION_FAILED ="417 Expectation Failed";
- public static String SC_FAILED_DEPENDENCY ="424 Failed Dependency";
- public static String SC_FORBIDDEN ="403 Forbidden";
- public static String SC_FOUND ="302 Found";
- public static String SC_GATEWAY_TIMEOUT ="504 Gateway Timeout";
- public static String SC_GONE ="410 Gone";
- public static String SC_HTTP_VERSION_NOT_SUPPORTED ="505 HTTP Version Not Supported";
- public static String SC_INSUFFICIENT_STORAGE ="507 Insufficient Storage";
- public static String SC_INTERNAL_SERVER_ERROR ="500 Server Error";
- public static String SC_LENGTH_REQUIRED ="411 Length Required";
- public static String SC_LOCKED ="423 Locked";
- public static String SC_METHOD_NOT_ALLOWED ="405 Method Not Allowed";
- public static String SC_MOVED_PERMANENTLY ="301 Moved Permanently";
- public static String SC_MOVED_TEMPORARILY ="302 Moved Temporarily";
- public static String SC_MULTI_STATUS ="207 Multi-Status";
- public static String SC_MULTIPLE_CHOICES ="300 Multiple Choices";
- public static String SC_NO_CONTENT ="204 No Content";
- public static String SC_NON_AUTHORITATIVE_INFORMATION ="203 Non Authoritative Information";
- public static String SC_NOT_ACCEPTABLE ="406 Not Acceptable";
- public static String SC_NOT_FOUND ="404 Not Found";
- public static String SC_NOT_IMPLEMENTED ="501 Not Implemented";
- public static String SC_NOT_MODIFIED ="304 Not Modified";
- public static String SC_OK ="200 OK";
- public static String SC_PARTIAL_CONTENT ="206 Partial Content";
- public static String SC_PAYMENT_REQUIRED ="402 Payment Required";
- public static String SC_PRECONDITION_FAILED ="412 Precondition Failed";
- public static String SC_PROCESSING ="102 Processing";
- public static String SC_PROXY_AUTHENTICATION_REQUIRED ="407 Proxy Authentication Required";
- public static String SC_REQUEST_ENTITY_TOO_LARGE ="413 Request Entity Too Large";
- public static String SC_REQUEST_TIMEOUT ="408 Request Timeout";
- public static String SC_REQUEST_URI_TOO_LONG ="414 Request-URI Too Long";
- public static String SC_REQUESTED_RANGE_NOT_SATISFIABLE ="416 Requested Range Not Satisfiable";
- public static String SC_RESET_CONTENT ="205 Reset Content";
- public static String SC_SEE_OTHER ="303 See Other";
- public static String SC_SERVICE_UNAVAILABLE ="503 Service Unavailable";
- public static String SC_SWITCHING_PROTOCOLS ="101 Switching Protocols";
- public static String SC_TEMPORARY_REDIRECT ="307 Temporary Redirect";
- public static String SC_UNAUTHORIZED ="401 Unauthorized";
- public static String SC_UNPROCESSABLE_ENTITY ="422 Unprocessable Entity";
- public static String SC_UNSUPPORTED_MEDIA_TYPE ="415 Unsupported Media Type";
- public static String SC_USE_PROXY ="305 Use Proxy";
+ public static String SC_ACCEPTED = "202 Accepted";
+ public static String SC_BAD_GATEWAY = "502 Bad Gateway";
+ public static String SC_BAD_REQUEST = "400 Bad Request";
+ public static String SC_CONFLICT = "409 Conflict";
+ public static String SC_CONTINUE = "100 Continue";
+ public static String SC_CREATED = "201 Created";
+ public static String SC_EXPECTATION_FAILED = "417 Expectation Failed";
+ public static String SC_FAILED_DEPENDENCY = "424 Failed Dependency";
+ public static String SC_FORBIDDEN = "403 Forbidden";
+ public static String SC_FOUND = "302 Found";
+ public static String SC_GATEWAY_TIMEOUT = "504 Gateway Timeout";
+ public static String SC_GONE = "410 Gone";
+ public static String SC_HTTP_VERSION_NOT_SUPPORTED = "505 HTTP Version Not Supported";
+ public static String SC_INSUFFICIENT_STORAGE = "507 Insufficient Storage";
+ public static String SC_INTERNAL_SERVER_ERROR = "500 Server Error";
+ public static String SC_LENGTH_REQUIRED = "411 Length Required";
+ public static String SC_LOCKED = "423 Locked";
+ public static String SC_METHOD_NOT_ALLOWED = "405 Method Not Allowed";
+ public static String SC_MOVED_PERMANENTLY = "301 Moved Permanently";
+ public static String SC_MOVED_TEMPORARILY = "302 Moved Temporarily";
+ public static String SC_MULTI_STATUS = "207 Multi-Status";
+ public static String SC_MULTIPLE_CHOICES = "300 Multiple Choices";
+ public static String SC_NO_CONTENT = "204 No Content";
+ public static String SC_NON_AUTHORITATIVE_INFORMATION = "203 Non Authoritative Information";
+ public static String SC_NOT_ACCEPTABLE = "406 Not Acceptable";
+ public static String SC_NOT_FOUND = "404 Not Found";
+ public static String SC_NOT_IMPLEMENTED = "501 Not Implemented";
+ public static String SC_NOT_MODIFIED = "304 Not Modified";
+ public static String SC_OK = "200 OK";
+ public static String SC_PARTIAL_CONTENT = "206 Partial Content";
+ public static String SC_PAYMENT_REQUIRED = "402 Payment Required";
+ public static String SC_PRECONDITION_FAILED = "412 Precondition Failed";
+ public static String SC_PROCESSING = "102 Processing";
+ public static String SC_PROXY_AUTHENTICATION_REQUIRED = "407 Proxy Authentication Required";
+ public static String SC_REQUEST_ENTITY_TOO_LARGE = "413 Request Entity Too Large";
+ public static String SC_REQUEST_TIMEOUT = "408 Request Timeout";
+ public static String SC_REQUEST_URI_TOO_LONG = "414 Request-URI Too Long";
+ public static String SC_REQUESTED_RANGE_NOT_SATISFIABLE = "416 Requested Range Not Satisfiable";
+ public static String SC_RESET_CONTENT = "205 Reset Content";
+ public static String SC_SEE_OTHER = "303 See Other";
+ public static String SC_SERVICE_UNAVAILABLE = "503 Service Unavailable";
+ public static String SC_SWITCHING_PROTOCOLS = "101 Switching Protocols";
+ public static String SC_TEMPORARY_REDIRECT = "307 Temporary Redirect";
+ public static String SC_UNAUTHORIZED = "401 Unauthorized";
+ public static String SC_UNPROCESSABLE_ENTITY = "422 Unprocessable Entity";
+ public static String SC_UNSUPPORTED_MEDIA_TYPE = "415 Unsupported Media Type";
+ public static String SC_USE_PROXY = "305 Use Proxy";
}
View
198 com/dinamoproductions/wowow/server/http/handlers/FileSystemHttpHandler.java
@@ -12,136 +12,144 @@
import com.dinamoproductions.wowow.filesystem.*;
public class FileSystemHttpHandler extends AbstractHttpHandler {
- AbstractFile file=null;
-
- public boolean allowDirectoryBrowsing=false
- ;
+ AbstractFile file = null;
+
+ public boolean allowDirectoryBrowsing = false;
+
public FileSystemHttpHandler(HttpHeaderMatcher m, AbstractFile f) {
super(m);
- file=(AbstractFile)f;
+ file = (AbstractFile) f;
// TODO Auto-generated constructor stub
}
-
- public void handle(HttpRequest request) throws IOException, URISyntaxException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
- if(!this.httpHeaderMatcher.matchHeader(request)) return;
- String fullPath=request.getPathInfo().getPath();
- HttpResponse response=request.getResponse();
+ public void handle(HttpRequest request) throws IOException,
+ URISyntaxException, SecurityException, NoSuchMethodException,
+ IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException, InstantiationException {
+ if (!this.httpHeaderMatcher.matchHeader(request))
+ return;
+
+ String fullPath = request.getPathInfo().getPath();
+ HttpResponse response = request.getResponse();
+
+ String path = request.getPath().getRawPath();
+ AbstractFile fileOrDir = file.getFile(URLDecoder.decode(path));
- String path=request.getPath().getRawPath();
- AbstractFile fileOrDir=file.getFile(URLDecoder.decode(path));
-
boolean isDirectory = fileOrDir.isDirectory();
- if(!fullPath.endsWith("/")&&isDirectory&&allowDirectoryBrowsing){
- response.redirect(request, fullPath+"/");
+ if (!fullPath.endsWith("/") && isDirectory && allowDirectoryBrowsing) {
+ response.redirect(request, fullPath + "/");
return;
}
- if(isDirectory&&allowDirectoryBrowsing){
- handleDirectoryListing(request, fileOrDir, response);
- }else if(!isDirectory){
+ if (isDirectory && allowDirectoryBrowsing) {
+ handleDirectoryListing(request, fileOrDir, response);
+ } else if (!isDirectory) {
handleContentDownload(request, response, fileOrDir);
}
-
+
}
private void handleContentDownload(HttpRequest request,
- HttpResponse response, AbstractFile fileOrDir)
- throws IOException {
- int start=0;
- int end=0;
- if(fileOrDir.exists()){
+ HttpResponse response, AbstractFile fileOrDir) throws IOException {
+ int start = 0;
+ int end = 0;
+ if (fileOrDir.exists()) {
String sContentRange = request.getHeader("range:");
- response.statusCode=StatusCodes.SC_OK;
+ response.statusCode = StatusCodes.SC_OK;
-
- long len=fileOrDir.length();
- long partialLen=len;
+ long len = fileOrDir.length();
+ long partialLen = len;
response.setHeader("Accept-Ranges:", "bytes");
- response.setHeader("Last-Modified:", HttpDate.rfc1123Format.format(fileOrDir.lastModified()));
-
- HttpCacheControl httpCacheControl=request.getHttpCacheControl();
-
- if(!httpCacheControl.ifNotModified){
- response.inputStream=fileOrDir.openInputStream();
- if(sContentRange!=null){
- if(sContentRange.startsWith("bytes=")){
- String sRange=sContentRange.substring(6);
- start=0;
+ response.setHeader("Last-Modified:",
+ HttpDate.rfc1123Format.format(fileOrDir.lastModified()));
+
+ HttpCacheControl httpCacheControl = request.getHttpCacheControl();
+
+ if (!httpCacheControl.ifNotModified) {
+ response.inputStream = fileOrDir.openInputStream();
+ if (sContentRange != null) {
+ if (sContentRange.startsWith("bytes=")) {
+ String sRange = sContentRange.substring(6);
+ start = 0;
String[] split = sRange.split("-");
int available = response.inputStream.available();
-
- start=0;
- end=available-1;
-
- if(sRange.startsWith("-")){
- end=Integer.parseInt(split[1]);
- }else if (sRange.endsWith("-")){
- start=Integer.parseInt(split[0]);
- }else if (sRange.contains("-")){
- start=Integer.parseInt(split[0]);
- end=Integer.parseInt(split[1]);
+
+ start = 0;
+ end = available - 1;
+
+ if (sRange.startsWith("-")) {
+ end = Integer.parseInt(split[1]);
+ } else if (sRange.endsWith("-")) {
+ start = Integer.parseInt(split[0]);
+ } else if (sRange.contains("-")) {
+ start = Integer.parseInt(split[0]);
+ end = Integer.parseInt(split[1]);
}
- if(start>0){
+ if (start > 0) {
response.inputStream.skip(start);
}
-
- partialLen = (end-start)+1;
- if(partialLen!=len){
- response.statusCode=StatusCodes.SC_PARTIAL_CONTENT;
-
+
+ partialLen = (end - start) + 1;
+ if (partialLen != len) {
+ response.statusCode = StatusCodes.SC_PARTIAL_CONTENT;
+
}
- response.setHeader("Content-Range:", "bytes " + start +"-"+(end)+"/"+len);
+ response.setHeader("Content-Range:", "bytes " + start
+ + "-" + (end) + "/" + len);
}
- }
- response.setHeader("Content-Length:", Long.toString(partialLen,10));
+ }
+ response.setHeader("Content-Length:",
+ Long.toString(partialLen, 10));
}
- request.handled=true;
-
+ request.handled = true;
+
}
}
- String html=null;
- String item=null;
- private void getHTML(){
- if(html!=null)return;
- InputStream ddis=getClass().getResourceAsStream("dir.html");
- html=utils.ChannelTools.convertStreamToString(ddis);
- String[] htmls=html.split("%%");
- html=htmls[0];
- item=htmls[1];
+
+ String html = null;
+ String item = null;
+
+ private void getHTML() {
+ if (html != null)
+ return;
+ InputStream ddis = getClass().getResourceAsStream("dir.html");
+ html = utils.ChannelTools.convertStreamToString(ddis);
+ String[] htmls = html.split("%%");
+ html = htmls[0];
+ item = htmls[1];
}
- private void handleDirectoryListing(HttpRequest request, AbstractFile fileOrDir, HttpResponse response) throws IOException, URISyntaxException {
- response.statusCode=StatusCodes.SC_OK;
+
+ private void handleDirectoryListing(HttpRequest request,
+ AbstractFile fileOrDir, HttpResponse response) throws IOException,
+ URISyntaxException {
+ response.statusCode = StatusCodes.SC_OK;
getHTML();
- String items="";
-
+ String items = "";
+
String path = request.getPathInfo().getPath();
- for(String f: fileOrDir.list()){
- AbstractFile nf=fileOrDir.getFile(f);
- String size="";
- Date mod=new Date(nf.lastModified());
- String fe=URLEncoder.encode(f);
- if(nf.isDirectory())
- {
- f+="/";
- }else{
- size=Long.toString(nf.length())+" bytes";
+ for (String f : fileOrDir.list()) {
+ AbstractFile nf = fileOrDir.getFile(f);
+ String size = "";
+ Date mod = new Date(nf.lastModified());
+ String fe = URLEncoder.encode(f);
+ if (nf.isDirectory()) {
+ f += "/";
+ } else {
+ size = Long.toString(nf.length()) + " bytes";
}
- items+=item.replace("%PATHITEM%", path+fe)
- .replace("%ITEM%", f)
- .replace("%MOD%",mod.toString())
- .replace("%SIZE%",size);
+ items += item.replace("%PATHITEM%", path + fe).replace("%ITEM%", f)
+ .replace("%MOD%", mod.toString()).replace("%SIZE%", size);
}
- String htmlo=html.replace("%ITEMS%", items);
- htmlo=htmlo.replace("%PATH%", path);
-
-
- BufferedInputStream is = new BufferedInputStream(new ByteArrayInputStream(htmlo.getBytes()));
-
+ String htmlo = html.replace("%ITEMS%", items);
+ htmlo = htmlo.replace("%PATH%", path);
+
+ BufferedInputStream is = new BufferedInputStream(
+ new ByteArrayInputStream(htmlo.getBytes()));
+
response.setHeader("Content-Type", "text/plain; charset=iso-8859-1");
- response.inputStream=is;
- request.handled=true;
+ response.inputStream = is;
+ request.handled = true;
}
}
View
6 com/dinamoproductions/wowow/server/utils.java
@@ -32,9 +32,9 @@ public static void streamCopy(final InputStream is, OutputStream os)
fastChannelCopy((ReadableByteChannel) Channels.newChannel(is),
(WritableByteChannel) Channels.newChannel(os));
}
-
- public static String convertStreamToString(InputStream is) {
- return new Scanner(is).useDelimiter("\\A").next();
+
+ public static String convertStreamToString(InputStream is) {
+ return new Scanner(is).useDelimiter("\\A").next();
}
}
}

0 comments on commit ebd59b5

Please sign in to comment.