Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,120 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
@:coreApi
class File {
public static function getContent(path:String):String {
var f = read(path, false);
var ret = f.readAll().toString();
f.close();
return ret;
}
public static function saveContent(path:String, content:String):Void {
var f = write(path, false);
f.writeString(content);
f.close();
}
public static function getBytes(path:String):haxe.io.Bytes {
var f = read(path, true);
var ret = f.readAll();
f.close();
return ret;
}
public static function saveBytes(path:String, bytes:haxe.io.Bytes):Void {
var f = write(path, true);
f.writeBytes(bytes, 0, bytes.length);
f.close();
}
public static function read(path:String, binary:Bool = true):FileInput {
try {
return @:privateAccess new FileInput(new java.io.RandomAccessFile(new java.io.File(path), "r"));
} catch (e:Dynamic) {
// swallow checked exceptions
throw e;
}
}
public static function write(path:String, binary:Bool = true):FileOutput {
var f = new java.io.File(path);
if (f.exists()) {
f.delete();
}
try {
return @:privateAccess new FileOutput(new java.io.RandomAccessFile(f, "rw"));
} catch (e:Dynamic) {
// swallow checked exceptions
throw e;
}
}
public static function append(path:String, binary:Bool = true):FileOutput {
var f = new java.io.File(path);
try {
var ra = new java.io.RandomAccessFile(f, "rw");
if (f.exists()) {
ra.seek(f.length());
}
return @:privateAccess new FileOutput(ra);
} catch (e:Dynamic) {
// swallow checked exceptions
throw e;
}
}
public static function update(path:String, binary:Bool = true):FileOutput {
var f = new java.io.File(path);
try {
var ra = new java.io.RandomAccessFile(f, "rw");
return @:privateAccess new FileOutput(ra);
} catch (e:Dynamic) {
// swallow checked exceptions
throw e;
}
}
public static function copy(srcPath:String, dstPath:String):Void {
var r:FileInput = null;
var w:FileOutput = null;
try {
r = read(srcPath);
w = write(dstPath);
w.writeInput(r);
r.close();
w.close();
} catch (e:Dynamic) {
if (r != null)
r.close();
if (w != null)
w.close();
throw e;
}
}
}

View File

@ -0,0 +1,111 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
import haxe.Int64;
import haxe.io.Bytes;
import haxe.io.Eof;
import haxe.io.Input;
import java.io.EOFException;
import java.io.IOException;
class FileInput extends Input {
var f:java.io.RandomAccessFile;
var _eof:Bool;
function new(f) {
this.f = f;
this._eof = false;
}
override public function close() {
try
f.close()
catch (e:Dynamic)
throw e;
}
override public function readByte():Int {
try {
return f.readUnsignedByte();
} catch (e:EOFException) {
_eof = true;
throw new Eof();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
var ret = 0;
try {
ret = f.read(s.getData(), pos, len);
} catch (e:EOFException) {
_eof = true;
throw new Eof();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
if (ret == -1) {
_eof = true;
throw new Eof();
}
return ret;
}
public function seek(p:Int, pos:FileSeek):Void {
_eof = false;
try {
switch (pos) {
case SeekBegin:
f.seek(cast p);
case SeekCur:
f.seek(haxe.Int64.add(f.getFilePointer(), cast(p, Int64)));
case SeekEnd:
f.seek(haxe.Int64.add(f.length(), cast p));
}
} catch (e:EOFException) {
_eof = true;
throw new Eof();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
public function tell():Int {
try {
return cast f.getFilePointer();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
public inline function eof():Bool {
return _eof;
}
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
import haxe.io.Bytes;
import haxe.io.Eof;
import haxe.io.Output;
import java.io.EOFException;
import java.io.IOException;
class FileOutput extends Output {
var f:java.io.RandomAccessFile;
function new(f) {
this.f = f;
}
override public function close() {
try
f.close()
catch (e:Dynamic)
throw e;
}
override public function writeByte(c:Int):Void {
try {
this.f.write(c);
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
override public function write(s:Bytes):Void {
try {
this.f.write(s.getData());
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
override public function writeBytes(s:Bytes, pos:Int, len:Int):Int {
try {
this.f.write(s.getData(), pos, len);
return len;
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
public function seek(p:Int, pos:FileSeek):Void {
try {
switch (pos) {
case SeekBegin:
f.seek(cast p);
case SeekCur:
f.seek(haxe.Int64.add(f.getFilePointer(), cast(p, haxe.Int64)));
case SeekEnd:
f.seek(haxe.Int64.add(f.length(), cast p));
}
} catch (e:EOFException) {
throw new Eof();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
public function tell():Int {
try {
return cast f.getFilePointer();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
}

View File

@ -0,0 +1,176 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
import haxe.SysTools;
import haxe.io.Bytes;
import haxe.io.BytesInput;
import haxe.io.Eof;
import java.io.IOException;
import java.io.EOFException;
import java.NativeArray;
@:coreApi
class Process {
public var stdout(default, null):haxe.io.Input;
public var stderr(default, null):haxe.io.Input;
public var stdin(default, null):haxe.io.Output;
private var proc:java.lang.Process;
@:allow(Sys)
private static function createProcessBuilder(cmd:String, ?args:Array<String>):java.lang.ProcessBuilder {
var sysName = Sys.systemName();
var pargs;
if (args == null) {
var cmdStr = cmd;
switch (sysName) {
case "Windows":
pargs = new NativeArray(3);
pargs[0] = cmd = switch (Sys.getEnv("COMSPEC")) {
case null: "cmd.exe";
case var comspec: comspec;
}
pargs[1] = '/C';
pargs[2] = '"$cmdStr"';
case _:
pargs = new NativeArray(3);
pargs[0] = cmd = "/bin/sh";
pargs[1] = "-c";
pargs[2] = cmdStr;
}
} else {
pargs = new NativeArray(args.length + 1);
switch (sysName) {
case "Windows":
pargs[0] = SysTools.quoteWinArg(cmd, false);
for (i in 0...args.length) {
pargs[i + 1] = SysTools.quoteWinArg(args[i], false);
}
case _:
pargs[0] = cmd;
for (i in 0...args.length) {
pargs[i + 1] = args[i];
}
}
}
return new java.lang.ProcessBuilder(pargs);
}
public function new(cmd:String, ?args:Array<String>, ?detached:Bool):Void {
if (detached)
throw "Detached process is not supported on this platform";
var p = proc = createProcessBuilder(cmd, args).start();
stderr = new ProcessInput(p.getErrorStream());
stdout = new ProcessInput(p.getInputStream());
stdin = new java.io.NativeOutput(p.getOutputStream());
}
public function getPid():Int {
if (Reflect.hasField(proc, "pid"))
return Reflect.field(proc, "pid");
return -1;
}
public function exitCode(block:Bool = true):Null<Int> {
if (block == false) {
try {
return proc.exitValue();
} catch (e:Dynamic) {
return null;
}
}
cast(stdout, ProcessInput).bufferContents();
cast(stderr, ProcessInput).bufferContents();
try {
proc.waitFor();
} catch (e:Dynamic) {
throw e;
}
return proc.exitValue();
}
public function close():Void {
proc.destroy();
}
public function kill():Void {
proc.destroy();
}
}
private class ProcessInput extends java.io.NativeInput {
private var chained:BytesInput;
public function bufferContents():Void {
if (chained != null)
return;
var b = this.readAll();
chained = new BytesInput(b);
}
override public function readByte():Int {
if (chained != null)
return chained.readByte();
var ret = 0;
try {
ret = stream.read();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
if (ret == -1)
throw new Eof();
return ret;
}
override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
if (chained != null)
return chained.readBytes(s, pos, len);
var ret = -1;
try {
ret = stream.read(s.getData(), pos, len);
} catch (e:EOFException) {
throw new Eof();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
if (ret == -1)
throw new Eof();
return ret;
}
override public function close():Void {
if (chained != null)
chained.close();
try {
stream.close();
} catch (e:IOException) {
throw haxe.io.Error.Custom(e);
}
}
}