TextFileReadStream.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.*;
import Hoot.Magnitudes.Integer;
import Hoot.Runtime.Names.Primitive;
import Hoot.Collections.CharacterString;
import Hoot.Runtime.Functions.Exceptional.Handler;
import Smalltalk.Magnitudes.Ordinal;
import Smalltalk.Collections.ReadableString;
import Smalltalk.Collections.CollectedReadably;
import Smalltalk.Streams.*;
public class TextFileReadStream extends FileReadStream<Character>
{
public static Metaclass type() { return (Metaclass)Metaclass.$class; }
@Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
public static class Metaclass extends FileReadStream.Metaclass
{
static final TextFileReadStream.Metaclass $class = new TextFileReadStream.Metaclass();
public Metaclass() {
this(TextFileReadStream.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return TextFileReadStream.class; }
/**
* @return
*/
public TextFileReadStream on(final RandomAccessFile primitiveFile)
{
java.lang.String exitID = "TextFileReadStreamMetatype>>on";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (TextFileReadStream)f0.exit(exitID, new TextFileReadStream(primitiveFile));
});
}
}
/**
*
*/
protected TextFileReadStream(final RandomAccessFile primitiveFile)
{
super(primitiveFile);
java.lang.String exitID = "TextFileReadStream>>TextFileReadStream";
Frame f0 = new Frame(exitID);
}
/**
* @return
*/
public static TextFileReadStream read(final String fileName)
{
java.lang.String exitID = "TextFileReadStream>>$read";
Frame f0 = new Frame(exitID);
return (TextFileReadStream)FileReadStream.type().read(fileName);
}
/**
* @return
*/
public String contents()
{
java.lang.String exitID = "TextFileReadStream>>contents";
Frame f0 = new Frame(exitID);
Integer pose = this.position();
this.reset();
String result = this.nextString(this.length());
this.position(pose);
return (String)result;
}
/**
* @return
*/
public Boolean isText()
{
java.lang.String exitID = "TextFileReadStream>>isText";
Frame f0 = new Frame(exitID);
return (Boolean)True.literal();
}
/**
* @return
*/
public Boolean isBinary()
{
java.lang.String exitID = "TextFileReadStream>>isBinary";
Frame f0 = new Frame(exitID);
return (Boolean)False.literal();
}
/**
* @return
*/
public Symbol externalType()
{
java.lang.String exitID = "TextFileReadStream>>externalType";
Frame f0 = new Frame(exitID);
return (Symbol)Symbol.from("text");
}
/**
* @return
*/
public String next(final Ordinal count)
{
java.lang.String exitID = "TextFileReadStream>>next";
Frame f0 = new Frame(exitID);
return (String)this.nextString(((Integer)count));
}
/**
* @return
*/
public String nextLine()
{
java.lang.String exitID = "TextFileReadStream>>nextLine";
Frame f0 = new Frame(exitID);
return (String)Closure.with(f2 -> {
return String.from(file.readLine());
}, "").defaultIfCurtailed(String.emptyString());
}
/**
* @return
*/
public Character next()
{
java.lang.String exitID = "TextFileReadStream>>next";
Frame f0 = new Frame(exitID);
return (Character)Closure.with(f2 -> {
return Character.from(((char)file.readUnsignedByte()));
}, "").defaultIfCurtailed(Character.type().nullCode());
}
/**
* @return
*/
public String upTo(final Character target)
{
java.lang.String exitID = "TextFileReadStream>>upTo";
Frame f0 = new Frame(exitID);
String result = String.emptyString();
while(!(this.atEnd().asPrimitive())) {
Character c = this.next();
if (target.equals(c).asPrimitive()) {
return result;
};
result.add(c);
};
return (String)result;
}
}