FileWriteStream.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 static Hoot.Streams.WriteStream.*;
import Hoot.Runtime.Names.Primitive;
import static Hoot.Runtime.Names.Primitive.*;
import Hoot.Exceptions.FileCheckError;
import Smalltalk.Collections.CollectedReadably;
import Smalltalk.Collections.ReadableString;
import Smalltalk.Streams.*;
public abstract class FileWriteStream<ElementType extends Object> extends FileStream<ElementType> implements FileStreamWriter<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 FileStreamWriter.Metatype
{
static final FileWriteStream.Metaclass $class = new FileWriteStream.Metaclass();
public Metaclass() {
this(FileWriteStream.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return FileWriteStream.class; }
/**
* @return
*/
public FileWriteStream write(final ReadableString fileName)
{
java.lang.String exitID = "FileWriteStreamMetatype>>write";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (FileWriteStream)f0.exit(exitID, this.write_mode(fileName, Symbol.from("create")));
});
}
/**
* @return
*/
public FileWriteStream write_type(final ReadableString fileName, final ReadableString fileType)
{
java.lang.String exitID = "FileWriteStreamMetatype>>write_type";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (FileWriteStream)f0.exit(exitID, this.open_type_mode_check(((String)fileName), ((Symbol)fileType), Symbol.from("create"), False.literal()));
});
}
/**
* @return
*/
public FileWriteStream write_mode(final ReadableString fileName, final ReadableString mode)
{
java.lang.String exitID = "FileWriteStreamMetatype>>write_mode";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (FileWriteStream)f0.exit(exitID, this.open_type_mode_check(((String)fileName), Symbol.from("text"), ((Symbol)mode), False.literal()));
});
}
/**
* @return
*/
public FileWriteStream write_mode_check_type(final ReadableString fileName, final ReadableString mode, final Posit check, final ReadableString fileType)
{
java.lang.String exitID = "FileWriteStreamMetatype>>write_mode_check_type";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (FileWriteStream)f0.exit(exitID, this.open_type_mode_check(((String)fileName), ((Symbol)fileType), ((Symbol)mode), ((Boolean)check)));
});
}
/**
* @return
*/
public FileWriteStream open_type_mode_check(final String fileName, final Symbol fileType, final Symbol mode, final Boolean check)
{
java.lang.String exitID = "FileWriteStreamMetatype>>open_type_mode_check";
Frame f0 = new Frame(exitID);
File file = new File(fileName.primitiveString());
if (file.exists()) {
if (check.primitiveBoolean()) {
if (CreateMode.equals(mode.primitiveString())) {
FileCheckError.type().presentFile(fileName);
return null;
};
};
}
else {
if (check.primitiveBoolean()) {
if (!(CreateMode.equals(mode.primitiveString()))) {
FileCheckError.type().missingFile(fileName);
return null;
};
};
};
if ("binary".equals(fileType.primitiveString())) {
return BinaryFileWriteStream.type().on(Primitive.writeFile(fileName.primitiveString(), mode.primitiveString()));
};
return TextFileWriteStream.type().on(Primitive.writeFile(fileName.primitiveString(), mode.primitiveString()));
}
}
/**
*
*/
public FileWriteStream(final RandomAccessFile primitiveFile)
{
super(primitiveFile);
java.lang.String exitID = "FileWriteStream>>FileWriteStream";
Frame f0 = new Frame(exitID);
}
/**
* @return
*/
public FileWriteStream flush()
{
java.lang.String exitID = "FileWriteStream>>flush";
Frame f0 = new Frame(exitID);
return (FileWriteStream)this;
}
/**
* @return
*/
public FileWriteStream cr()
{
java.lang.String exitID = "FileWriteStream>>cr";
Frame f0 = new Frame(exitID);
this.nextPutAll(((CollectedReadably)LineSeparator));
return (FileWriteStream)this;
}
/**
* @return
*/
public FileWriteStream tab()
{
java.lang.String exitID = "FileWriteStream>>tab";
Frame f0 = new Frame(exitID);
this.nextPut(((ElementType)Character.type().tab()));
return (FileWriteStream)this;
}
/**
* @return
*/
public FileWriteStream space()
{
java.lang.String exitID = "FileWriteStream>>space";
Frame f0 = new Frame(exitID);
this.nextPut(((ElementType)Character.type().space()));
return (FileWriteStream)this;
}
/**
* @return
*/
public FileWriteStream nextPutLine(final String line)
{
java.lang.String exitID = "FileWriteStream>>nextPutLine";
Frame f0 = new Frame(exitID);
{
FileWriteStream prime = this;
prime.nextPutAll(line);
prime.cr();
};
return (FileWriteStream)this;
}
}