Skip to content
Open
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
Expand Up @@ -26,7 +26,7 @@ struct JavaKitArrayRuntimeTests {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)

let bytes: [Int8] = arrays.getFixedBytes()
let bytes: [UInt8] = arrays.getFixedBytes()
#expect(bytes == [1, 2, 3, 4, 5])
}

Expand All @@ -36,7 +36,7 @@ struct JavaKitArrayRuntimeTests {
let arrays = HelloJavaKitArrays(environment: env)

// snippet.arraysUsage
let reversed: [Int8] = arrays.reverseBytes([10, 20, 30])
let reversed: [UInt8] = arrays.reverseBytes([10, 20, 30])
#expect(reversed == [30, 20, 10])
// snippet.end
}
Expand All @@ -55,7 +55,7 @@ struct JavaKitArrayRuntimeTests {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)

let bytes: [Int8] = arrays.getEmptyBytes()
let bytes: [UInt8] = arrays.getEmptyBytes()
#expect(bytes.isEmpty)
}

Expand All @@ -64,7 +64,7 @@ struct JavaKitArrayRuntimeTests {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)

let bytes: [Int8] = arrays.filledBytes(4, 42)
let bytes: [UInt8] = arrays.filledBytes(4, 42)
#expect(bytes == [42, 42, 42, 42])
}

Expand All @@ -91,7 +91,7 @@ struct JavaKitArrayRuntimeTests {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)

let bytes: [Int8] = arrays.stringToBytes("Hi")
let bytes: [UInt8] = arrays.stringToBytes("Hi")
// "Hi" in UTF-8 is [0x48, 0x69]
#expect(bytes == [0x48, 0x69])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ open class BufferedInputStream: InputStream {
/// public synchronized int java.io.BufferedInputStream.read(byte[],int,int) throws java.io.IOException
/// ```
@JavaMethod
open override func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32
open override func read(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) throws -> Int32

/// Java method `reset`.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/JavaStdlib/JavaUtil/generated/BitSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension JavaClass<BitSet> {
/// public static java.util.BitSet java.util.BitSet.valueOf(byte[])
/// ```
@JavaStaticMethod
public func valueOf(_ arg0: [Int8]) -> BitSet!
public func valueOf(_ arg0: [UInt8]) -> BitSet!

/// Java method `valueOf`.
///
Expand Down Expand Up @@ -252,7 +252,7 @@ open class BitSet: JavaObject {
/// public byte[] java.util.BitSet.toByteArray()
/// ```
@JavaMethod
open func toByteArray() -> [Int8]
open func toByteArray() -> [UInt8]

/// Java method `toLongArray`.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ open class JarInputStream: InputStream {
/// public int java.util.jar.JarInputStream.read(byte[],int,int) throws java.io.IOException
/// ```
@JavaMethod
open override func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32
open override func read(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) throws -> Int32
}
4 changes: 2 additions & 2 deletions Sources/JavaStdlib/JavaUtilJar/generated/ZipEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ open class ZipEntry: JavaObject {
/// public byte[] java.util.zip.ZipEntry.getExtra()
/// ```
@JavaMethod
open func getExtra() -> [Int8]
open func getExtra() -> [UInt8]

/// Java method `setExtra`.
///
Expand All @@ -96,7 +96,7 @@ open class ZipEntry: JavaObject {
/// public void java.util.zip.ZipEntry.setExtra(byte[])
/// ```
@JavaMethod
open func setExtra(_ arg0: [Int8])
open func setExtra(_ arg0: [UInt8])

/// Java method `getMethod`.
///
Expand Down
22 changes: 11 additions & 11 deletions Sources/SwiftJava/generated/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension JavaClass<ByteBuffer> {
/// public static java.nio.ByteBuffer java.nio.ByteBuffer.wrap(byte[])
/// ```
@JavaStaticMethod
public func wrap(_ arg0: [Int8]) -> ByteBuffer!
public func wrap(_ arg0: [UInt8]) -> ByteBuffer!

/// Java method `wrap`.
///
Expand All @@ -36,7 +36,7 @@ extension JavaClass<ByteBuffer> {
/// public static java.nio.ByteBuffer java.nio.ByteBuffer.wrap(byte[],int,int)
/// ```
@JavaStaticMethod
public func wrap(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) -> ByteBuffer!
public func wrap(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) -> ByteBuffer!
}
/// Java `sealed class`, permits: `java.nio.HeapByteBuffer`, `java.nio.MappedByteBuffer`
@JavaClass("java.nio.ByteBuffer")
Expand Down Expand Up @@ -66,7 +66,7 @@ open class ByteBuffer: JavaObject {
/// public final byte[] java.nio.ByteBuffer.array()
/// ```
@JavaMethod
open func array() -> [Int8]
open func array() -> [UInt8]

/// Java method `arrayOffset`.
///
Expand Down Expand Up @@ -228,7 +228,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.get(byte[])
/// ```
@JavaMethod
open func get(_ arg0: [Int8]) -> ByteBuffer!
open func get(_ arg0: [UInt8]) -> ByteBuffer!

/// Java method `get`.
///
Expand All @@ -237,7 +237,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.get(byte[],int,int)
/// ```
@JavaMethod
open func get(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) -> ByteBuffer!
open func get(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) -> ByteBuffer!

/// Java method `get`.
///
Expand All @@ -246,7 +246,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.get(int,byte[])
/// ```
@JavaMethod
open func get(_ arg0: Int32, _ arg1: [Int8]) -> ByteBuffer!
open func get(_ arg0: Int32, _ arg1: [UInt8]) -> ByteBuffer!

/// Java method `get`.
///
Expand All @@ -255,7 +255,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.get(int,byte[],int,int)
/// ```
@JavaMethod
open func get(_ arg0: Int32, _ arg1: [Int8], _ arg2: Int32, _ arg3: Int32) -> ByteBuffer!
open func get(_ arg0: Int32, _ arg1: [UInt8], _ arg2: Int32, _ arg3: Int32) -> ByteBuffer!

/// Java method `hasArray`.
///
Expand Down Expand Up @@ -363,7 +363,7 @@ open class ByteBuffer: JavaObject {
/// public final java.nio.ByteBuffer java.nio.ByteBuffer.put(byte[])
/// ```
@JavaMethod
open func put(_ arg0: [Int8]) -> ByteBuffer!
open func put(_ arg0: [UInt8]) -> ByteBuffer!

/// Java method `put`.
///
Expand All @@ -372,7 +372,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.put(byte[],int,int)
/// ```
@JavaMethod
open func put(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) -> ByteBuffer!
open func put(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) -> ByteBuffer!

/// Java method `put`.
///
Expand All @@ -381,7 +381,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.put(int,byte[])
/// ```
@JavaMethod
open func put(_ arg0: Int32, _ arg1: [Int8]) -> ByteBuffer!
open func put(_ arg0: Int32, _ arg1: [UInt8]) -> ByteBuffer!

/// Java method `put`.
///
Expand All @@ -390,7 +390,7 @@ open class ByteBuffer: JavaObject {
/// public java.nio.ByteBuffer java.nio.ByteBuffer.put(int,byte[],int,int)
/// ```
@JavaMethod
open func put(_ arg0: Int32, _ arg1: [Int8], _ arg2: Int32, _ arg3: Int32) -> ByteBuffer!
open func put(_ arg0: Int32, _ arg1: [UInt8], _ arg2: Int32, _ arg3: Int32) -> ByteBuffer!

/// Java method `put`.
///
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftJava/generated/InputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open class InputStream: JavaObject {
/// public int java.io.InputStream.read(byte[]) throws java.io.IOException
/// ```
@JavaMethod
open func read(_ arg0: [Int8]) throws -> Int32
open func read(_ arg0: [UInt8]) throws -> Int32

/// Java method `read`.
///
Expand All @@ -77,7 +77,7 @@ open class InputStream: JavaObject {
/// public int java.io.InputStream.read(byte[],int,int) throws java.io.IOException
/// ```
@JavaMethod
open func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32
open func read(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) throws -> Int32

/// Java method `readAllBytes`.
///
Expand All @@ -86,7 +86,7 @@ open class InputStream: JavaObject {
/// public byte[] java.io.InputStream.readAllBytes() throws java.io.IOException
/// ```
@JavaMethod
open func readAllBytes() throws -> [Int8]
open func readAllBytes() throws -> [UInt8]

/// Java method `readNBytes`.
///
Expand All @@ -95,7 +95,7 @@ open class InputStream: JavaObject {
/// public byte[] java.io.InputStream.readNBytes(int) throws java.io.IOException
/// ```
@JavaMethod
open func readNBytes(_ arg0: Int32) throws -> [Int8]
open func readNBytes(_ arg0: Int32) throws -> [UInt8]

/// Java method `readNBytes`.
///
Expand All @@ -104,7 +104,7 @@ open class InputStream: JavaObject {
/// public int java.io.InputStream.readNBytes(byte[],int,int) throws java.io.IOException
/// ```
@JavaMethod
open func readNBytes(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32
open func readNBytes(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) throws -> Int32

/// Java method `reset`.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftJava/generated/JavaClassLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ open class JavaClassLoader: JavaObject {
/// ```
@available(*, deprecated)
@JavaMethod
open func defineClass(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> JavaClass<JavaObject>!
open func defineClass(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) throws -> JavaClass<JavaObject>!

/// Java method `defineClass`.
///
Expand All @@ -111,7 +111,7 @@ open class JavaClassLoader: JavaObject {
/// protected final java.lang.Class<?> java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError
/// ```
@JavaMethod
open func defineClass(_ arg0: String, _ arg1: [Int8], _ arg2: Int32, _ arg3: Int32) throws -> JavaClass<JavaObject>!
open func defineClass(_ arg0: String, _ arg1: [UInt8], _ arg2: Int32, _ arg3: Int32) throws -> JavaClass<JavaObject>!

/// Java method `findClass`.
///
Expand Down
24 changes: 12 additions & 12 deletions Sources/SwiftJava/generated/JavaString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,30 @@ open class JavaString: JavaObject {
@_nonoverride public convenience init(environment: JNIEnvironment? = nil)

@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: [UInt8], environment: JNIEnvironment? = nil)

@available(*, deprecated)
@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: Int32, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: Int32, environment: JNIEnvironment? = nil)

@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32, environment: JNIEnvironment? = nil)

@available(*, deprecated)
@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32, _ arg3: Int32, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32, _ arg3: Int32, environment: JNIEnvironment? = nil)

@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32, _ arg3: String, environment: JNIEnvironment? = nil) throws
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32, _ arg3: String, environment: JNIEnvironment? = nil) throws

@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32, _ arg3: Charset?, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32, _ arg3: Charset?, environment: JNIEnvironment? = nil)

@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: String, environment: JNIEnvironment? = nil) throws
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: String, environment: JNIEnvironment? = nil) throws

@JavaMethod
@_nonoverride public convenience init(_ arg0: [Int8], _ arg1: Charset?, environment: JNIEnvironment? = nil)
@_nonoverride public convenience init(_ arg0: [UInt8], _ arg1: Charset?, environment: JNIEnvironment? = nil)

@JavaMethod
@_nonoverride public convenience init(_ arg0: [UInt16], environment: JNIEnvironment? = nil)
Expand Down Expand Up @@ -178,7 +178,7 @@ open class JavaString: JavaObject {
/// public byte[] java.lang.String.getBytes()
/// ```
@JavaMethod
open func getBytes() -> [Int8]
open func getBytes() -> [UInt8]

/// Java method `getBytes`.
///
Expand All @@ -187,7 +187,7 @@ open class JavaString: JavaObject {
/// public byte[] java.lang.String.getBytes(java.lang.String) throws java.io.UnsupportedEncodingException
/// ```
@JavaMethod
open func getBytes(_ arg0: String) throws -> [Int8]
open func getBytes(_ arg0: String) throws -> [UInt8]

/// Java method `getBytes`.
///
Expand All @@ -196,7 +196,7 @@ open class JavaString: JavaObject {
/// public byte[] java.lang.String.getBytes(java.nio.charset.Charset)
/// ```
@JavaMethod
open func getBytes(_ arg0: Charset?) -> [Int8]
open func getBytes(_ arg0: Charset?) -> [UInt8]

/// Java method `getBytes`.
///
Expand All @@ -206,7 +206,7 @@ open class JavaString: JavaObject {
/// ```
@available(*, deprecated)
@JavaMethod
open func getBytes(_ arg0: Int32, _ arg1: Int32, _ arg2: [Int8], _ arg3: Int32)
open func getBytes(_ arg0: Int32, _ arg1: Int32, _ arg2: [UInt8], _ arg3: Int32)

/// Java method `charAt`.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftJava/generated/OutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ open class OutputStream: JavaObject {
/// public void java.io.OutputStream.write(byte[]) throws java.io.IOException
/// ```
@JavaMethod
open func write(_ arg0: [Int8]) throws
open func write(_ arg0: [UInt8]) throws

/// Java method `write`.
///
Expand All @@ -59,5 +59,5 @@ open class OutputStream: JavaObject {
/// public void java.io.OutputStream.write(byte[],int,int) throws java.io.IOException
/// ```
@JavaMethod
open func write(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws
open func write(_ arg0: [UInt8], _ arg1: Int32, _ arg2: Int32) throws
}
4 changes: 1 addition & 3 deletions Sources/SwiftJavaToolLib/JavaClassTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ struct JavaClassTranslator {
if let inputStream = javaClass.getClassLoader()?.getResourceAsStream(resourcePath) {
do {
let bytes = try inputStream.readAllBytes()
self.runtimeInvisibleAnnotations = JavaClassFileReader.parseRuntimeInvisibleAnnotations(
bytes.map { UInt8(bitPattern: $0) }
)
self.runtimeInvisibleAnnotations = JavaClassFileReader.parseRuntimeInvisibleAnnotations(bytes)
let classCount = self.runtimeInvisibleAnnotations.classAnnotations.count
let methodCount = self.runtimeInvisibleAnnotations.methodAnnotations.count
let fieldCount = self.runtimeInvisibleAnnotations.fieldAnnotations.count
Expand Down
8 changes: 6 additions & 2 deletions Sources/SwiftJavaToolLib/JavaTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ package class JavaTranslator {
/// A mapping from the name of each known Java class to the corresponding
/// Swift type name and its Swift module.
package var translatedClasses: [JavaFullyQualifiedTypeName: SwiftTypeName] = [
"java.lang.Object": SwiftTypeName(module: "SwiftJava", name: "JavaObject"),
"byte[]": SwiftTypeName(module: nil, name: "[UInt8]"),
"java.lang.Object": SwiftTypeName(module: "SwiftJava", name: "JavaObject")
]

/// A mapping from the name of each known Java class with the Swift value type
Expand Down Expand Up @@ -327,6 +326,11 @@ extension JavaTranslator {
let swiftTypeName: String
if !preferValueTypes, case .array(_) = javaType {
swiftTypeName = try self.getSwiftTypeNameFromJavaClassName("java.lang.reflect.Array", preferValueTypes: false)
} else if case .array(.byte) = javaType {
// A Java byte[] is a byte buffer, for which Swift's idiomatic element type
// is UInt8; this also mirrors the export direction, where UInt8 maps to
// byte. Scalar byte stays Int8, matching Java's signed byte.
swiftTypeName = "[UInt8]"
} else {
swiftTypeName = try javaType.swiftTypeName { javaClassName in
try self.getSwiftTypeNameFromJavaClassName(javaClassName, preferValueTypes: preferValueTypes)
Expand Down
Loading