Advertisement
Guest User

IOException

a guest
Jun 12th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package com.companyname.wms.httpprovider;
  2.  
  3. import java.io.*;
  4. import java.util.List;
  5. import java.util.Map;
  6. //import com.wowza.util.Base64.*;
  7. import com.wowza.wms.vhost.IVHost;
  8. import com.wowza.wms.http.HTTPProvider2Base;
  9. import com.wowza.wms.http.IHTTPRequest;
  10. import com.wowza.wms.http.IHTTPResponse;
  11. import com.wowza.wms.logging.WMSLoggerFactory;
  12.  
  13.  
  14. public class Monitor extends HTTPProvider2Base {
  15.  
  16.     public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
  17.        
  18.         if (!doHTTPAuthentication(vhost, req, resp))
  19.             return;
  20.        
  21.         req.parseBodyForParams(true);
  22.            
  23.         Map<String, List<String>> params = req.getParameterMap();
  24.            
  25.         if (req.getQueryString()=="")
  26.         {
  27.             new FileResponder(resp, "/assets/wowza.html");
  28.         }
  29.         if (params.containsKey("file")) {
  30.             new FileResponder(resp, "/assets/" + params.get("file").get(0));
  31.         }
  32.     }
  33.     class FileResponder
  34.     {
  35.         FileResponder(IHTTPResponse resp, String loc)
  36.         {
  37.             try
  38.             {
  39.                InputStream is = this.getClass().getResourceAsStream(loc);
  40.                BufferedInputStream inf = new BufferedInputStream(is);
  41.                OutputStream out = resp.getOutputStream();
  42.  
  43.                byte[] bytes = new byte[4096];
  44.                while(true)
  45.                {
  46.                    int byteRead = inf.read(bytes);
  47.                    if (byteRead < 0)
  48.                            break;
  49.                    out.write(bytes, 0, byteRead);
  50.                }            
  51.             }
  52.             catch (Exception e)
  53.             {
  54.                 e.printStackTrace();
  55.             }          
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement