![JAR search and dependency download from the Maven repository](/logo.png)
org.anadix.factories.StringSource Maven / Gradle / Ivy
/*
* Copyright 2011 Tomas Schlosser
*
* 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 org.anadix.factories;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import org.anadix.Source;
class StringSource implements Source {
private final String source;
private final String description;
/**
* Constructor
*
* @param source - instance of String representing the source
*/
public StringSource(String source) {
this(source, null);
}
/**
* Constructor
*
* @param source - instance of String representing the source
* @param description - description of the source
*/
public StringSource(String source, String description) {
if (source == null) {
throw new NullPointerException("source can't be null");
}
this.source = source;
this.description = description;
}
/**
* {@inheritDoc}
*/
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
public String getText() {
return source;
}
/**
* {@inheritDoc}
*/
public Reader getReader() {
return new StringReader(source);
}
/**
* {@inheritDoc}
*/
public InputStream getStream() {
return new ByteArrayInputStream(source.getBytes());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy