001    package railo.commons.io.res.type.s3;
002    
003    import java.io.IOException;
004    import java.io.InputStream;
005    import java.security.InvalidKeyException;
006    import java.security.NoSuchAlgorithmException;
007    
008    import org.xml.sax.SAXException;
009    
010    public final class Content implements S3Info {
011            
012            
013            private String key;
014            private long lastModified;
015            private String eTag;
016            private long size;
017            private String storageClass;
018            private String ownerIdKey;
019            private String ownerDisplayName;
020            private String bucketName;
021            private final S3 s3;
022            private boolean truncated;
023            
024            /**
025             * @return the truncated
026             */
027            public boolean isTruncated() {
028                    return truncated;
029            }
030            /**
031             * @return the bucketName
032             */
033            public String getBucketName() {
034                    return bucketName;
035            }
036            /**
037             * @param bucketName the bucketName to set
038             */
039            public void setBucketName(String bucketName) {
040                    this.bucketName = bucketName;
041            }
042            public Content(S3 s3) {
043                    this.s3=s3;
044            }
045            /**
046             * @return the key
047             */
048            public String getKey() {
049                    return key;
050            }
051            /**
052             * @param key the key to set
053             */
054            public void setKey(String key) {
055                    this.key = key;
056            }
057            /**
058             * @return the lastModified
059             */
060            public long getLastModified() {
061                    return lastModified;
062            }
063            /**
064             * @param lastModified the lastModified to set
065             */
066            public void setLastModified(long lastModified) {
067                    this.lastModified = lastModified;
068            }
069            /**
070             * @return the eTag
071             */
072            public String getETag() {
073                    return eTag;
074            }
075            /**
076             * @param tag the eTag to set
077             */
078            public void setETag(String tag) {
079                    eTag = tag;
080            }
081            /**
082             * @return the size
083             */
084            public long getSize() {
085                    return size;
086            }
087            /**
088             * @param size the size to set
089             */
090            public void setSize(long size) {
091                    this.size = size;
092            }
093            /**
094             * @return the storageClass
095             */
096            public String getStorageClass() {
097                    return storageClass;
098            }
099            /**
100             * @param storageClass the storageClass to set
101             */
102            public void setStorageClass(String storageClass) {
103                    this.storageClass = storageClass;
104            }
105            /**
106             * @return the ownerIdKey
107             */
108            public String getOwnerIdKey() {
109                    return ownerIdKey;
110            }
111            /**
112             * @param ownerIdKey the ownerIdKey to set
113             */
114            public void setOwnerIdKey(String ownerIdKey) {
115                    this.ownerIdKey = ownerIdKey;
116            }
117            /**
118             * @return the ownerDisplayName
119             */
120            public String getOwnerDisplayName() {
121                    return ownerDisplayName;
122            }
123            /**
124             * @param ownerDisplayName the ownerDisplayName to set
125             */
126            public void setOwnerDisplayName(String ownerDisplayName) {
127                    this.ownerDisplayName = ownerDisplayName;
128            }
129            
130            public String getLink(int secondsValid) throws InvalidKeyException, NoSuchAlgorithmException, IOException {
131                    return s3.getObjectLink(bucketName, key, secondsValid);
132            }
133            
134            public InputStream getInputStream() throws InvalidKeyException, NoSuchAlgorithmException, IOException, SAXException {
135                    return s3.getInputStream(bucketName, key);
136            }
137            
138            
139            @Override
140            public String toString() {
141                    return "eTag:"+eTag+";key:"+key+";ownerDisplayName:"+ownerDisplayName+";ownerIdKey:"+ownerIdKey+";size:"+size+";storageClass:"+storageClass+";";
142            }
143            
144            @Override
145            public boolean exists() {
146                    return true;
147            }
148            
149            @Override
150            public boolean isDirectory() {
151                    return getSize()==0 && getKey().endsWith("/");
152            }
153            
154            @Override
155            public boolean isFile() {
156                    return getSize()>0 || !getKey().endsWith("/");
157            }
158            /**
159             * @param truncated the truncated to set
160             */
161            public void setTruncated(boolean truncated) {
162                    this.truncated = truncated;
163            }
164            
165            
166    }