at.spardat.xma.boot.transport.Result Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
/*
* Created on 16.05.2003
*/
package at.spardat.xma.boot.transport;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
* Result
-objects are used by the transport layer, to store server request results.
* it contains the result buffer and additional information about the resource.
*
* @author s2877, s3595
* @version $Id: Result.java 2084 2007-11-27 14:53:31Z s3460 $
*/
public class Result {
/**
* if the server returns an expiration date for the resource,
* it is stored in this member. the default is 0.
*/
long expirationDate_;
/**
* the last modified information returned from server.
*/
long lastModified_;
/**
* the length of the content returned from the server in bytes.
* this is equal to the buffer length.
*/
int contentLength_;
/**
* the ETag is used in combination with conditional gets from the server.
*/
String etag_;
/**
* list of transforming filters applied at the server side (e.g. compression, hash)
*/
String transformations_;
/**
* buffer that contains the server result as byte array.
*/
byte[] buffer_;
/** initialize members */
public Result() {
expirationDate_ = 0L;
lastModified_ = 0L;
contentLength_ = 0;
buffer_ = null;
etag_ = null;
transformations_ = null;
}
/**
* get an InputStream to read the resource.
*
* @return InputStream returns an input stream to the result buffer.
*/
public InputStream getContent() {
if(buffer_!=null) {
return new ByteArrayInputStream(buffer_);
} else {
throw new IllegalStateException( "result buffer is not initialized"); //$NON-NLS-1$
}
}
/**
* Get the ETag which is used for conditional gets from the server.
* @return String etag value
*/
public String getEtag() {
return etag_;
}
/**
* Does this result object contain a modified resource loaded from server ?
*
* @return true if the resource contains new data.
*/
public boolean isModified() {
return buffer_ != null;
}
/**
* Gets the length of the content returned from the server in bytes.
* @return contentLength buffer length
*/
public int getContentLength() {
return contentLength_;
}
/**
* Gets the expiration date of the resource as returned by the server.
* @return long the expiration date or 0 if no expiration date was returned by the server.
*/
public long getExpirationDate() {
return expirationDate_;
}
/**
* Gets the the last modified information returned from the server.
* @return long last modified
*/
public long getLastModified() {
return lastModified_;
}
/**
* Get the buffer containing the content data returned from the server.
* @return byte[] buffer
*/
public byte[] getBuffer() {
return buffer_;
}
/**
* Sets the buffer containing the data returned from the server. This method my only be called
* by an implementation of {@link Transport}.
* @param bs buffer
*/
void setBuffer(byte[] bs) {
buffer_ = bs;
}
/**
* Get the descripton of the list of transforming filters applied at the server side
* (e.g. compression, hash)
* @since 1.3.0
* @see at.spardat.xma.session.Transform
*/
public String getTransformations() {
return transformations_;
}
}