com.g2forge.alexandria.java.io.dataaccess.IDataSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.io.dataaccess;
import java.io.InputStream;
import java.io.Reader;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import com.g2forge.alexandria.annotations.message.TODO;
import com.g2forge.alexandria.java.io.HBinaryIO;
import com.g2forge.alexandria.java.io.HIO;
import com.g2forge.alexandria.java.type.ref.ITypeRef;
public interface IDataSource extends IDataAccess {
public default byte[] getBytes() {
return HBinaryIO.read(getStream(null));
}
@TODO(value = "Use static type switch", link = "G2-432")
public default T getReader(ITypeRef type) {
if ((type != null) && !Reader.class.equals(type.getErasedType())) throw new IllegalArgumentException();
@SuppressWarnings("unchecked")
final T retVal = (T) Channels.newReader(getChannel(ITypeRef.of(ReadableByteChannel.class)), Charset.defaultCharset().newDecoder(), -1);
return retVal;
}
@TODO(value = "Use static type switch", link = "G2-432")
public default T getStream(ITypeRef type) {
if ((type != null) && !InputStream.class.equals(type.getErasedType())) throw new IllegalArgumentException();
@SuppressWarnings("unchecked")
final T retVal = (T) Channels.newInputStream(getChannel(ITypeRef.of(ReadableByteChannel.class)));
return retVal;
}
public default String getString() {
return HIO.readAll(getStream(null), false);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy