Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.javaswift.joss.client.core;
  
 
 import java.io.File;
 import java.util.Date;
 
 public abstract class AbstractStoredObject extends AbstractObjectStoreEntity<ObjectInformationimplements StoredObject {
 
     protected String name;
 
     private String bareName;
 
     private Container container;
 
     private final StoredObjectCommandFactory commandFactory;
 
     public AbstractStoredObject(Container containerString nameboolean allowCaching) {
         super(allowCaching);
         this. = ((AbstractContainer)container).getFactory().getStoredObjectCommandFactory();
         this. = container;
         this. = name;
         this. = Directory.bareName(name.getDelimiter());
         this. = new ObjectInformation();
     }
 
     public void metadataSetFromHeaders() {
         this. = false;
     }
 
     public Date getLastModifiedAsDate() {
         checkForInfoAndAllowHeaderSet();
         return .getLastModifiedAsDate();
     }
 
     public String getLastModified() {
         checkForInfoAndAllowHeaderSet();
         return .getLastModified();
     }
 
     public String getEtag() {
         checkForInfoAndAllowHeaderSet();
         return .getEtag();
     }
 
     public long getContentLength() {
         checkForInfoAndAllowHeaderSet();
         return .getContentLength();
     }
 
     public String getContentType() {
         checkForInfoAndAllowHeaderSet();
         return .getContentType();
     }
 
     public Date getDeleteAtAsDate() {
         checkForInfo();
         return .getDeleteAt() == null ? null : .getDeleteAt().getDate();
     }
 
     public String getDeleteAt() {
         checkForInfo();
         return .getDeleteAt() == null ? null : .getDeleteAt().getHeaderValue();
     }
 
     public String getName() {
         return ;
     }
 
     public Container getContainer() {
         return ;
     }
 
     @Override
     public String getURL() {
         return getContainer().isPublic() ? getPublicURL() : getPrivateURL();
     }
 
     @Override
     public String getPublicURL() {
         return getContainer().getAccount().getPublicURL() + getPath();
     }
 
     @Override
     public String getPrivateURL() {
         return getContainer().getAccount().getPrivateURL() + getPath();
    }
    @Override
        return getContainer().getPath() + "/" + SpaceURLEncoder.encode(getName());
    }
    public void setLastModified(Date date) {
        this..setLastModified(new ObjectLastModified(date));
    }
    public void setLastModified(String date) {
        try {
            // The LastModified date in the JSON body differs from that in the response header
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            setLastModified(formatter.parse(date));
        } catch (ParseException e) {
            throw new CommandException("Unable to convert date string: "+datee);
        }
    }
    public void setEtag(String etag) {
        this..setEtag(new Etag(etag));
    }
    public void setContentLength(long contentLength) {
        this..setContentLength(new ObjectContentLength(Long.toString(contentLength)));
    }
    public void setContentTypeWithoutSaving(String contentType) {
        this..setContentType(new ObjectContentType(contentType));
    }
    public int hashCode() {
        return getName().hashCode();
    }
    public void uploadObject(UploadInstructions uploadInstructions) {
        if (uploadInstructions.requiresSegmentation()) {
            uploadObjectAsSegments(uploadInstructions);
        } else {
            directlyUploadObject(uploadInstructions);
        }
        invalidate();
    }
    public void uploadObjectAsSegments(UploadInstructions uploadInstructions) {
        ((AbstractContainer)getContainer()).uploadSegmentedObjects(getName(), uploadInstructions);
        // The manifest file is the handle which allows the ObjectStore to piece the segments together as one file
        UploadInstructions manifest = new UploadInstructions(new byte[] {})
                .setObjectManifest(new ObjectManifest(getPath().replaceFirst("/",""))) // Manifest does not accept preceding slash
                .setContentType(uploadInstructions.getContentType());
        uploadObject(manifest);
    }
    @SuppressWarnings("ConstantConditions")
    public boolean equals(Object o) {
        return o instanceof StoredObject && compareTo((StoredObjecto) == 0;
    }
    @SuppressWarnings("ConstantConditions")
    public int compareTo(DirectoryOrObject o) {
        int compareValue = getName().compareTo(o.getName());
        if (compareValue == 0 && o instanceof StoredObject) {
            compareValue = getContainer().compareTo(((AbstractStoredObjecto).getContainer());
        }
        return compareValue;
    }
    protected Metadata createMetadataEntry(String nameString value) {
        return new ObjectMetadata(namevalue);
    }
        return downloadObjectAsInputStream(new DownloadInstructions());
    }
    public InputStream downloadObjectAsInputStream(DownloadInstructions downloadInstructions) {
        return .createDownloadObjectAsInputStreamCommand(getAccount(), getContainer(), thisdownloadInstructions).call();
    }
    public byte[] downloadObject() {
        return downloadObject(new DownloadInstructions());
    }
    public byte[] downloadObject(DownloadInstructions downloadInstructions) {
        return .createDownloadObjectAsByteArrayCommand(getAccount(), getContainer(),thisdownloadInstructions).call();
    }
    public void downloadObject(File targetFile) {
        downloadObject(targetFilenew DownloadInstructions());
    }
    public void downloadObject(File targetFileDownloadInstructions downloadInstructions) {
        .createDownloadObjectToFileCommand(getAccount(), getContainer(),thisdownloadInstructionstargetFile).call();
    }
    public void directlyUploadObject(UploadInstructions uploadInstructions) {
        .createUploadObjectCommand(getAccount(), getContainer(), thisuploadInstructions).call();
    }
    public void uploadObject(InputStream inputStream) {
        uploadObject(new UploadInstructions(inputStream));
    }
    public void uploadObject(byte[] fileToUpload) {
        uploadObject(new UploadInstructions(fileToUpload));
    }
    public void uploadObject(File fileToUpload) {
        uploadObject(new UploadInstructions(fileToUpload));
    }
    public void delete() {
    }
    public void copyObject(Container targetContainerStoredObject targetObject) {
                getAccount(),
                getContainer(), this,
                ((AbstractStoredObject)targetObject).getContainer(), targetObject).call();
    }
    public StoredObject setContentType(String contentType) {
        checkForInfo();
        .setContentType(new ObjectContentType(contentType));
                getAccount(), getContainer(), this.getHeadersIncludingHeader(.getContentTypeHeader())).call();
        return this;
    }
    public StoredObject setDeleteAfter(long seconds) {
        checkForInfo();
        .setDeleteAt(null);
        .setDeleteAfter(new DeleteAfter(seconds));
                getAccount(), getContainer(), this.getHeadersIncludingHeader(.getDeleteAfter())).call();
        return this;
    }
    @Override
    public StoredObject setDeleteAt(Date date) {
        checkForInfo();
        .setDeleteAt(new DeleteAt(date));
        saveSpecificMetadata();
        return this;
    }
    protected Account getAccount() {
        return getContainer().getAccount();
    }
    @Override
    protected void saveSpecificMetadata() {
    }
    protected void getInfo(boolean allowErrorLog) {
        this. = .createObjectInformationCommand(getAccount(), getContainer(), thisallowErrorLog).call();
        this.setInfoRetrieved();
    }
    @Override
    public String getTempGetUrl(long durationInSeconds) {
        return getTempUrl("GET"durationInSeconds);
    }
    @Override
    public String getTempPutUrl(long durationInSeconds) {
        return getTempUrl("PUT"durationInSeconds);
    }
    protected String getTempUrl(String methodlong durationInSeconds) {
        return new TempURL(method.getTempUrlPrefix(), this)
                .setServerTimeExpiry(durationInSeconds)
                .getTempUrl();
    }
    @SuppressWarnings("SimplifiableIfStatement")
    @Override
    public boolean verifyTempUrl(String methodString signaturelong expiry) {
        return new TempURL(method.getTempUrlPrefix(), this)
                .setFixedExpiry(expiry)
                .verify(signatureexpiry);
    }
    public boolean isObject() { return true; }
    public boolean isDirectory() { return false; }
    @Override public Directory getAsDirectory() {
        throw new UnsupportedOperationException("A StoredObject cannot be cast to a Directory");
    }
    @Override public StoredObject getAsObject() {
        return this;
    }
    @Override public String getBareName() {
        return ;
    }
New to GrepCode? Check out our FAQ X