1 16 package org.apache.commons.vfs.provider; 17 18 import org.apache.commons.vfs.FileContent; 19 import org.apache.commons.vfs.FileSystemException; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 import java.net.URL ; 25 import java.net.URLConnection ; 26 27 32 public final class DefaultURLConnection 33 extends URLConnection 34 { 35 private final FileContent content; 36 37 public DefaultURLConnection(final URL url, 38 final FileContent content) 39 { 40 super(url); 41 this.content = content; 42 } 43 44 public void connect() 45 { 46 connected = true; 47 } 48 49 public InputStream getInputStream() 50 throws IOException 51 { 52 return content.getInputStream(); 53 } 54 55 public OutputStream getOutputStream() 56 throws IOException 57 { 58 return content.getOutputStream(); 59 } 60 61 public int getContentLength() 62 { 63 try 64 { 65 return (int) content.getSize(); 66 } 67 catch (FileSystemException fse) 68 { 69 } 70 71 return -1; 72 } 73 74 public String getContentType() 75 { 76 try 77 { 78 return content.getContentInfo().getContentType(); 79 } 80 catch (FileSystemException e) 81 { 82 throw new RuntimeException (e.getMessage()); 83 } 84 } 85 86 public String getContentEncoding() 87 { 88 try 89 { 90 return content.getContentInfo().getContentEncoding(); 91 } 92 catch (FileSystemException e) 93 { 94 throw new RuntimeException (e.getMessage()); 95 } 96 } 97 98 120 } 121 | Popular Tags |