MagStream.java

/**
* Copyright 2010,2023 Nikolas S Boyd.
Permission is granted to copy this work provided this copyright statement is retained in all copies.

*/
package Hoot.Tests;

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 Hoot.Streams.*;

public class MagStream extends TestableClosure
{

  protected Array sample = ((Array)Array.withAll(new Object[]{
    SmallInteger.from(9), SmallInteger.from(8), SmallInteger.from(7), SmallInteger.from(6), SmallInteger.from(5), SmallInteger.from(4), SmallInteger.from(3), SmallInteger.from(2), SmallInteger.from(1), SmallInteger.from(0)
  }));

  /**
   * @return 
   */
  @Override public   void runTest()
  {
    java.lang.String exitID = "MagStream>>runTest";
    Frame f0 = new Frame(exitID);
    OrderedCollection o = OrderedCollection.type().withAll(sample);

    ReadStream rStream = o.readStream();

    OrderedCollection m = OrderedCollection.type().$new();
    m.registerType(SmallInteger.from(0));

    WriteStream wStream = m.writeStream();
    Predicate.with(f2 -> {
      return rStream.atEnd();
    }, "").whileFalse(Closure.with(f2 -> {
      
    SmallInteger n = ((SmallInteger)rStream.next());
    wStream.nextPut(n);
    this.log().print(n.printString());
    }, ""));
    wStream.close();
    rStream.close();
    this.log().printLine();
    this.log().printLine(wStream.contents().size().printString());
  }
}