All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wings.template.StreamTemplateSource Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings.template;

import java.io.IOException;
import java.io.InputStream;

/**
 * A StreamDataSource implements a DataSource
 * as a wrapper around a Stream.
 *
 * @author Joachim Karrer
 */
public class StreamTemplateSource implements TemplateSource {
    /**
     * enable debug output
     */
    private static final boolean DEBUG = true;

    /**
     * 

the InputStream from which we are reading data.

*/ private transient InputStream iStream; /** *

the last time the InputStream was updated.

*/ private long modificationTime; /** *

generates a new StreamDataSource with the given Stream

* * @param iStream the InputStream from which the template is read. */ public StreamTemplateSource(InputStream iStream) { setInputStream(iStream); } /** *

sets the InputStream and the modificationTime

* * @param iStream the InputStream from which the template is read. */ public void setInputStream(InputStream iStream) { if (iStream == null) { throw new IllegalArgumentException("stream is null, this is invalid!!"); } this.iStream = iStream; setModificationTime(); } /** *

sets the modificationTime to the currentTimeMillis

*/ public void setModificationTime() { modificationTime = System.currentTimeMillis(); } /** *

returns the canonical name of the inputStream (uaaaah!)

* * @return

always null, because stream is always to be parsed

*/ @Override public String getCanonicalName() { return null; } /** *

Returns the time the content of this stream * was last modified.

*

The return value is used to decide whether to reparse a * Source or not. Reparsing is done if the value returned * here differs from the value returned at the last processing * time.

*

Attention: Modificationtime is only updated if a new stream is set!

* * @return long a modification time */ @Override public long lastModified() { return modificationTime; } /** * Gets an InputStream of the File. * * @return the actually set InputStream */ @Override public InputStream getInputStream() throws IOException { iStream.reset(); return iStream; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy