/*
* Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.semagia.atomico.server.impl.restlet.resources;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import org.restlet.data.MediaType;
import org.restlet.representation.StreamRepresentation;
import com.semagia.atomico.dm.IWritable;
/**
* Representation that utilizes a {@link IWritable} for the output.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
* @version $Rev: 66 $ - $Date: 2010-09-06 08:29:07 -0700 (Mon, 06 Sep 2010) $
*/
final class WritableAwareRepresentation extends StreamRepresentation {
private final IWritable _writer;
/**
* Initializes an instance.
*
* @param mediaType The media type which is written by the <tt>writer</tt>.
* @param writer The writer.
* @param modificationTime The modification time of the representation.
*/
public WritableAwareRepresentation(final MediaType mediaType,
final IWritable writer, final long modificationTime) {
super(mediaType);
_writer = writer;
setModificationDate(new Date(modificationTime));
}
/* (non-Javadoc)
* @see org.restlet.resource.Representation#getStream()
*/
@Override
public InputStream getStream() throws IOException {
return null;
}
/* (non-Javadoc)
* @see org.restlet.resource.Representation#write(java.io.OutputStream)
*/
@Override
public void write(OutputStream out) throws IOException {
_writer.write(out);
}
}
|