1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.net.URL;
23 import java.net.URLConnection;
24
25 import org.apache.commons.io.function.Uncheck;
26 import org.apache.commons.vfs2.FileContent;
27 import org.apache.commons.vfs2.FileSystemException;
28
29
30
31
32 public final class DefaultURLConnection extends URLConnection {
33
34 private final FileContent fileContent;
35
36
37
38
39
40
41
42 public DefaultURLConnection(final URL url, final FileContent fileContent) {
43 super(url);
44 this.fileContent = fileContent;
45 }
46
47 @Override
48 public void connect() {
49 connected = true;
50 }
51
52 @Override
53 public String getContentEncoding() {
54 return Uncheck.get(() -> fileContent.getContentInfo().getContentEncoding());
55 }
56
57 @Override
58 public int getContentLength() {
59 try {
60 return (int) fileContent.getSize();
61 } catch (final FileSystemException fse) {
62 return -1;
63 }
64 }
65
66 @Override
67 public String getContentType() {
68 return Uncheck.get(() -> fileContent.getContentInfo().getContentType());
69 }
70
71 @Override
72 public InputStream getInputStream() throws IOException {
73 return fileContent.getInputStream();
74 }
75
76 @Override
77 public long getLastModified() {
78 try {
79 return fileContent.getLastModifiedTime();
80 } catch (final FileSystemException ignored) {
81 return -1;
82 }
83 }
84
85 @Override
86 public OutputStream getOutputStream() throws IOException {
87 return fileContent.getOutputStream();
88 }
89
90
91
92
93
94
95
96
97 }