NativeOutput.hx 818 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package sys.io;
  2. import haxe.Int64;
  3. import haxe.io.Bytes;
  4. import haxe.io.Eof;
  5. import haxe.io.Output;
  6. import java.io.Exceptions;
  7. class NativeOutput extends Output
  8. {
  9. var stream:java.io.OutputStream;
  10. public function new(stream)
  11. {
  12. this.stream = stream;
  13. }
  14. override public function writeByte(c:Int):Void
  15. {
  16. try
  17. {
  18. stream.write(c);
  19. }
  20. catch (e:EOFException) {
  21. throw new Eof();
  22. }
  23. catch (e:IOException) {
  24. throw haxe.io.Error.Custom(e);
  25. }
  26. }
  27. override public function close():Void
  28. {
  29. try
  30. {
  31. stream.close();
  32. }
  33. catch (e:IOException) {
  34. throw haxe.io.Error.Custom(e);
  35. }
  36. }
  37. override public function flush():Void
  38. {
  39. try
  40. {
  41. stream.flush();
  42. }
  43. catch (e:IOException) {
  44. throw haxe.io.Error.Custom(e);
  45. }
  46. }
  47. }