Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .bytes import * as Bytes
bytes = Bytes
'''
from .request import Request
from .request import Request
from .request import Request
from .response import Response

request = Request
response = Response
'''

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# SPDX-License-Identifier: EPL-2.0

from java.lang import String, Byte
import java.lang.reflect.Array as JArray

import java

class Bytes:
BytesFacade = java.type('org.eclipse.dirigible.components.api.io')
@staticmethod
def toJavaBytes(bytes):
internalBytes = JArray.newInstance(Byte.TYPE, len(bytes))
for i in range(len(bytes)):
internalBytes[i] = bytes[i]
return internalBytes

@staticmethod
def toJavaScriptBytes(internalBytes):
bytes = []
for i in range(internalBytes.length):
bytes.append(internalBytes[i])
return bytes

@staticmethod
def textToByteArray(text):
javaString = String(text)
native = BytesFacade.textToByteArray(text)
return toJavaScriptBytes(native)

@staticmethod
def byteArrayToText(data):
native = toJavaBytes(data)
return "".join(map(chr, toJavaScriptBytes(native)))

@staticmethod
def intToByteArray(value, byteOrder):
return BytesFacade.intToByteArray(value, byteOrder)

@staticmethod
def byteArrayToInt(data, byteOrder):
return BytesFacade.byteArrayToInt(data, byteOrder)
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# SPDX-License-Identifier: EPL-2.0

import streams
import bytes
import java

class Files:
FilesFacade = java.type("org.eclipse.dirigible.components.api.io.FilesFacade")

@staticmethod
def exists(path):
return FilesFacade.exists(path)

@staticmethod
def isExecutable(path):
return FilesFacade.isExecutable(path)

@staticmethod
def isReadable(path):
return FilesFacade.isReadable(path)

@staticmethod
def isWritable(path):
return FilesFacade.isWritable(path)

@staticmethod
def isHidden(path):
return FilesFacade.isHidden(path)

@staticmethod
def isDirectory(path):
return FilesFacade.isDirectory(path)

@staticmethod
def isFile(path):
return FilesFacade.isFile(path)

@staticmethod
def isSameFile(path1, path2):
return FilesFacade.isSameFile(path1, path2)

@staticmethod
def getCanonicalPath(path):
return FilesFacade.getCanonicalPath(path)

@staticmethod
def getName(path):
return FilesFacade.getName(path)

@staticmethod
def getParentPath(path):
return FilesFacade.getParentPath(path)

@staticmethod
def readBytes(path):
native = FilesFacade.readBytes(path)
data = bytes.toPythonBytes(native)
return data

@staticmethod
def readBytesNative(path):
return FilesFacade.readBytes(path)

@staticmethod
def readText(path):
return FilesFacade.readText(path)

@staticmethod
def writeBytes(path, data):
native = bytes.toJavaBytes(data)
FilesFacade.writeBytesNative(path, native)

@staticmethod
def writeBytesNative(path, data):
FilesFacade.writeBytesNative(path, data)

@staticmethod
def writeText(path, text):
FilesFacade.writeText(path, text)

@staticmethod
def getLastModified(path):
return FilesFacade.getLastModified(path)

@staticmethod
def setLastModified(path, time):
FilesFacade.setLastModified(path, time.getMilliseconds())

@staticmethod
def getOwner(path):
return FilesFacade.getOwner(path)

@staticmethod
def setOwner(path, owner):
FilesFacade.setOwner(path, owner)

@staticmethod
def getPermissions(path):
return FilesFacade.getPermissions(path)

@staticmethod
def setPermissions(path, permissions):
FilesFacade.setPermissions(path, permissions)

@staticmethod
def size(path):
return FilesFacade.size(path)

@staticmethod
def createFile(path):
FilesFacade.createFile(path)

@staticmethod
def createDirectory(path):
FilesFacade.createDirectory(path)

@staticmethod
def copy(source, target):
FilesFacade.copy(source, target)

@staticmethod
def move(source, target):
FilesFacade.move(source, target)

@staticmethod
def deleteFile(path):
FilesFacade.deleteFile(path)

@staticmethod
def deleteDirectory(path, forced):
FilesFacade.deleteDirectory(path, forced)

@staticmethod
def createTempFile(prefix, suffix):
return FilesFacade.createTempFile(prefix, suffix)

@staticmethod
def createTempDirectory(prefix):
return FilesFacade.createTempDirectory(prefix)

@staticmethod
def createInputStream(path):
native = FilesFacade.createInputStream(path)
return streams.InputStream(native)

@staticmethod
def createOutputStream(path):
native = FilesFacade.createOutputStream(path)
return streams.OutputStream(native)

@staticmethod
def traverse(path):
return FilesFacade.traverse(path)

@staticmethod
def list(path):
return list(map(lambda e: e['path'], JSON.parse(FilesFacade.list(path))))

@staticmethod
def find(path, pattern):
return JSON.parse(FilesFacade.find(path, pattern))
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# SPDX-License-Identifier: EPL-2.0

import streams
import java

class Image:
ImageFacade = java.type("org.eclipse.dirigible.components.api.io.ImageFacade")

@staticmethod
def resize(original, imageType, width, height):
native = ImageFacade.resize(original, imageType, width, height)
return streams.InputStream(native)
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v20.html
# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
# SPDX-License-Identifier: EPL-2.0

import bytes
import java

StreamsFacade = java.type("org.eclipse.dirigible.components.api.io.StreamsFacade")

class InputStream:
@staticmethod
def __init__(self, native):
self.native = native

@staticmethod
def read(self):
return StreamsFacade.read(self.native)

@staticmethod
def readBytes(self):
native = StreamsFacade.readBytes(self.native)
return bytes.toPythonBytes(native)

@staticmethod
def readBytesNative(self):
return StreamsFacade.readBytes(self.native)

@staticmethod
def readText(self):
return StreamsFacade.readText(self.native)

@staticmethod
def close(self):
StreamsFacade.close(self.native)

@staticmethod
def isValid(self):
return self.native is not None

class OutputStream:
@staticmethod
def __init__(self, native):
self.native = native

@staticmethod
def write(self, byte):
StreamsFacade.write(self.native, byte)

@staticmethod
def writeBytes(self, data):
native = bytes.toJavaBytes(data)
StreamsFacade.writeBytes(self.native, native)

@staticmethod
def writeBytesNative(self, data):
StreamsFacade.writeBytes(self.native, data)

@staticmethod
def writeText(self, text):
StreamsFacade.writeText(self.native, text)

@staticmethod
def close(self):
StreamsFacade.close(self.native)

@staticmethod
def getBytes(self):
native = StreamsFacade.getBytes(self.native)
data = bytes.toPythonBytes(native)
return data

@staticmethod
def getBytesNative(self):
native = StreamsFacade.getBytes(self.native)
return native

@staticmethod
def getText(self):
value = StreamsFacade.getText(self.native)
return value

@staticmethod
def isValid(self):
return self.native is not None

def copy(input, output):
StreamsFacade.copy(input.native, output.native)

def copyLarge(input, output):
StreamsFacade.copyLarge(input.native, output.native)

def getResourceAsByteArrayInputStream(path):
native = StreamsFacade.getResourceAsByteArrayInputStream(path)
return InputStream(native)

def createByteArrayInputStream(data):
array = bytes.toJavaBytes(data)
native = StreamsFacade.createByteArrayInputStream(array)
return InputStream(native)

def createByteArrayOutputStream():
native = StreamsFacade.createByteArrayOutputStream()
return OutputStream(native)

def createInputStream(native):
inputStream = InputStream(native)
return inputStream

def createOutputStream(native):
outputStream = OutputStream(native)
return outputStream
Loading