FileReadStream.java
/**
* Copyright 2010,2021 Nikolas S Boyd.
Permission is granted to copy this work provided this copyright statement is retained in all copies.
*/
package Hoot.Streams;
import Hoot.Runtime.Functions.*;
import Hoot.Runtime.Faces.*;
import Hoot.Runtime.Values.*;
import Hoot.Runtime.Blocks.*;
import Smalltalk.Core.*;
import Smalltalk.Blocks.*;
import Smalltalk.Magnitudes.*;
import Hoot.Behaviors.*;
import Hoot.Behaviors.Nil;
import Hoot.Behaviors.Object;
import Hoot.Behaviors.True;
import Hoot.Behaviors.False;
import Hoot.Behaviors.Boolean;
import Hoot.Magnitudes.*;
import Hoot.Magnitudes.Integer;
import Hoot.Magnitudes.Character;
import Hoot.Magnitudes.Float;
import Hoot.Magnitudes.Double;
import Hoot.Collections.*;
import Hoot.Collections.String;
import java.io.RandomAccessFile;
import Hoot.Magnitudes.Integer;
import Hoot.Runtime.Names.Primitive;
import static Hoot.Streams.WriteStream.*;
import Smalltalk.Magnitudes.Ordinal;
import Smalltalk.Collections.CollectedReadably;
import Smalltalk.Collections.ReadableString;
import Smalltalk.Streams.*;
public abstract class FileReadStream<ElementType extends Object> extends FileStream<ElementType> implements FileStreamReader<ElementType>
{
public static Metaclass type() { return (Metaclass)Metaclass.$class; }
@Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
public static class Metaclass extends FileStream.Metaclass implements FileStreamReader.Metatype
{
static final FileReadStream.Metaclass $class = new FileReadStream.Metaclass();
public Metaclass() {
this(FileReadStream.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return FileReadStream.class; }
/**
* @return
*/
public FileReadStream read(final ReadableString fileName)
{
java.lang.String exitID = "FileReadStreamMetatype>>read";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (FileReadStream)f0.exit(exitID, this.read_type(fileName, Symbol.from("text")));
});
}
/**
* @return
*/
public FileReadStream read_type(final ReadableString fileName, final ReadableString fileType)
{
java.lang.String exitID = "FileReadStreamMetatype>>read_type";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (FileReadStream)f0.exit(exitID, this.open_type(((String)fileName), ((Symbol)fileType)));
});
}
/**
* @return
*/
public FileReadStream open_type(final String fileName, final Symbol fileType)
{
java.lang.String exitID = "FileReadStreamMetatype>>open_type";
Frame f0 = new Frame(exitID);
if ("binary".equals(fileType.primitiveString())) {
return BinaryFileReadStream.type().on(Primitive.readFile(fileName.primitiveString()));
};
return TextFileReadStream.type().on(Primitive.readFile(fileName.primitiveString()));
}
}
/**
*
*/
public FileReadStream(final RandomAccessFile primitiveFile)
{
super(primitiveFile);
java.lang.String exitID = "FileReadStream>>FileReadStream";
Frame f0 = new Frame(exitID);
}
/**
* @return
*/
public FileReadStream skip(final Ordinal count)
{
java.lang.String exitID = "FileReadStream>>skip";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
Closure.with(f2 -> {
file.skipBytes(count.intValue());
return (FileReadStream)f0.exit(exitID, null);
}, "").runLoud();
return (FileReadStream)this;
});
}
/**
* @return
*/
public Boolean skipTo(final ElementType target)
{
java.lang.String exitID = "FileReadStream>>skipTo";
Frame f0 = new Frame(exitID);
Predicate.with(f2 -> {
return (target.equals(this.next()));
}, "").whileFalse(Closure.with(f2 -> {
}, ""));
return (Boolean)True.literal();
}
/**
* @return
*/
public Boolean nextMatchFor(final ElementType target)
{
java.lang.String exitID = "FileReadStream>>nextMatchFor";
Frame f0 = new Frame(exitID);
return (Boolean)(this.next().equals(target));
}
/**
* @return
*/
public Boolean peekFor(final ElementType target)
{
java.lang.String exitID = "FileReadStream>>peekFor";
Frame f0 = new Frame(exitID);
return (Boolean)(this.peek().equals(target));
}
/**
* @return
*/
public ElementType peek()
{
java.lang.String exitID = "FileReadStream>>peek";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
this.atEnd().ifTrue(Closure.with(f2 -> {
return (ElementType)f0.exit(exitID, Nil.literal());
}, ""));
Integer position = this.position();
ElementType result = this.next();
this.position(position);
return (ElementType)f0.exit(exitID, result);
});
}
/**
* @return
*/
public FileReadStream $do(final MonadicValuable aBlock)
{
java.lang.String exitID = "FileReadStream>>$do";
Frame f0 = new Frame(exitID);
Predicate.with(f2 -> {
return this.atEnd();
}, "").whileFalse(Closure.with(f2 -> {
return aBlock.value(this.next());
}, ""));
return (FileReadStream)this;
}
}