-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding Runtime.exec Adding Runtime and Proccess on Java side and Runtime and cpproc on c side, cpproc is responsible to execute the command and Runtime is responsible to make the Streams and make the Proccess to be returned. * FileInputChannel implementation * Creating FileInputStream and and returning the Proccess with it * Fixing stream to use byte array instead of ByteBuffer on java side * Binding OutputStream and ErrorStream * Set file descriptors to the value returned from cpproc_forkAndExec * OutputStream and ErrorStream * Calling cpproc_forAndExec with correct values * Fixing malloc and strings * Testing with filePath NULL * Runtime.exec working without path. * Updating Runtime interface and adding filePath to Runtime.c * Forgotten chdir * Adding exitValue, waitFor and destroy. * Changing memory allocation to heap on Runtime and fixing some exceptions This change was made so It's easier to deallocate the char pointers used to pass the command, path and environment arrays to cpproc_forkAndExec Co-authored-by: flsobral <flsobral@gmail.com> * Adding exception to reads with error value on return and changing byteBuffer to byteArray for better readability * Adding exception to windows, android and iOS and adding the file to CMakeLists on android Co-authored-by: Allan C <acmlira@gmail.com> Co-authored-by: flsobral <flsobral@gmail.com>
- Loading branch information
1 parent
f40718e
commit ab17b15
Showing
24 changed files
with
967 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
TotalCrossSDK/src/main/java/jdkcompat/io/FileInputStream4D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.io; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import jdkcompat.nio.channels.FileChannelImpl4D; | ||
|
||
|
||
public class FileInputStream4D extends InputStream { | ||
FileChannelImpl4D fileChannel; | ||
|
||
FileInputStream4D(FileChannelImpl4D fileChannel) { | ||
this.fileChannel = fileChannel; | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
return fileChannel.read(); | ||
} | ||
|
||
@Override | ||
public int read(byte[] dst) throws IOException { | ||
return fileChannel.read(dst, 0, dst.length); | ||
} | ||
|
||
@Override | ||
public int read(byte[] dsts, int offset, int length) throws IOException { | ||
return fileChannel.read(dsts, offset, length); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
fileChannel.close(); | ||
} | ||
|
||
@Override | ||
public int available() throws IOException { | ||
return fileChannel.available(); | ||
} | ||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
TotalCrossSDK/src/main/java/jdkcompat/io/FileOutputStream4D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.io; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import jdkcompat.nio.channels.FileChannelImpl4D; | ||
|
||
public class FileOutputStream4D extends OutputStream { | ||
|
||
FileChannelImpl4D fileChannel; | ||
|
||
FileOutputStream4D(FileChannelImpl4D fileChannel) { | ||
this.fileChannel = fileChannel; | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
fileChannel.write(b, off, len); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
TotalCrossSDK/src/main/java/jdkcompat/lang/IllegalThreadStateException4D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.lang; | ||
|
||
public class IllegalThreadStateException4D extends IllegalArgumentException { | ||
|
||
public IllegalThreadStateException4D() { | ||
|
||
} | ||
|
||
public IllegalThreadStateException4D(String s) { | ||
super(s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.lang; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public abstract class Process4D { | ||
|
||
boolean isAlive; | ||
|
||
public abstract void destroy(); | ||
|
||
public Process4D destroyForcibly() { | ||
return this; | ||
} | ||
|
||
public abstract int exitValue(); | ||
|
||
public abstract InputStream getErrorStream(); | ||
|
||
public abstract InputStream getInputStream(); | ||
|
||
public abstract OutputStream getOutputStream(); | ||
|
||
public boolean isAlive() { | ||
return isAlive; | ||
} | ||
|
||
public abstract int waitFor(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
TotalCrossSDK/src/main/java/jdkcompat/lang/ProcessImpl4D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.lang; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class ProcessImpl4D extends Process { | ||
|
||
InputStream inputStream; | ||
OutputStream outputStream; | ||
InputStream errorStream; | ||
int pid; | ||
|
||
@Override | ||
native public void destroy(); | ||
|
||
@Override | ||
native public int exitValue(); | ||
|
||
@Override | ||
public InputStream getErrorStream() { | ||
return this.errorStream; | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() { | ||
return this.inputStream; | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() { | ||
return this.outputStream; | ||
} | ||
|
||
@Override | ||
native public int waitFor(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.lang; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
|
||
import totalcross.sys.Convert; | ||
|
||
public class Runtime4D { | ||
|
||
private static Runtime4D instance; | ||
|
||
private Runtime4D() { | ||
|
||
} | ||
|
||
public static Runtime4D getRuntime() { | ||
if(instance == null) { | ||
instance = new Runtime4D(); | ||
} | ||
return instance; | ||
} | ||
|
||
native private Process exec(String[] cmdarray, String[] envp, String dirPath); | ||
|
||
public Process exec(String[] cmdarray, String[] envp, File dir) { | ||
return exec(cmdarray, envp, dir.getPath()); | ||
} | ||
|
||
public Process exec(String[] cmdarray, String[] envp) { | ||
String dirPath = null; | ||
return exec(cmdarray, envp, dirPath); | ||
} | ||
|
||
public Process exec(String[] cmdarray) { | ||
return exec(cmdarray, null); | ||
} | ||
|
||
public Process exec(String command, String[] envp, File dir) { | ||
return exec(Convert.tokenizeString(command, ' '), envp, dir.getPath()); | ||
} | ||
|
||
public Process exec(String command, String[] envp) { | ||
String dirPath = null; | ||
return exec(Convert.tokenizeString(command, ' '), envp, dirPath); | ||
} | ||
|
||
public Process exec(String command) { | ||
return exec(command, null); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
TotalCrossSDK/src/main/java/jdkcompat/nio/channels/FileChannel4D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.nio.channels; | ||
|
||
import java.io.Closeable; | ||
|
||
public abstract class FileChannel4D implements Closeable{ | ||
|
||
|
||
} |
140 changes: 140 additions & 0 deletions
140
TotalCrossSDK/src/main/java/jdkcompat/nio/channels/FileChannelImpl4D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Copyright (C) 2000-2013 SuperWaba Ltda. | ||
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-only | ||
|
||
package jdkcompat.nio.channels; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.MappedByteBuffer; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.FileLock; | ||
import java.nio.channels.ReadableByteChannel; | ||
import java.nio.channels.WritableByteChannel; | ||
|
||
public class FileChannelImpl4D extends FileChannel { | ||
|
||
private int nfd = -1; | ||
|
||
FileChannelImpl4D(int fd) { | ||
this.nfd = fd; | ||
} | ||
|
||
FileChannelImpl4D() { | ||
|
||
} | ||
|
||
native public int read() throws IOException; | ||
|
||
public int available() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int read(ByteBuffer dst) throws IOException { | ||
return 0; | ||
} | ||
|
||
native public int read(byte[] dst, int offset, int length) throws IOException; | ||
|
||
@Override | ||
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
|
||
native public int write(byte[] src, int offset, int length) throws IOException; | ||
|
||
@Override | ||
public int write(ByteBuffer src) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long position() throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public FileChannel position(long newPosition) throws IOException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public long size() throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public FileChannel truncate(long size) throws IOException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public void force(boolean metaData) throws IOException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public long transferTo(long position, long count, WritableByteChannel target) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int read(ByteBuffer dst, long position) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int write(ByteBuffer src, long position) throws IOException { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
@Override | ||
public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public FileLock lock(long position, long size, boolean shared) throws IOException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public FileLock tryLock(long position, long size, boolean shared) throws IOException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void implCloseChannel() throws IOException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.