diff --git a/Package.swift b/Package.swift index 72a95155..42b74041 100644 --- a/Package.swift +++ b/Package.swift @@ -76,6 +76,11 @@ let package = Package( targets: ["JavaKitNetwork"] ), + .library( + name: "JavaKitIO", + targets: ["JavaKitIO"] + ), + .library( name: "JavaKitReflection", targets: ["JavaKitReflection"] @@ -241,6 +246,15 @@ let package = Package( .unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]) ] ), + .target( + name: "JavaKitIO", + dependencies: ["JavaKit", "JavaKitCollection"], + exclude: ["swift-java.config"], + swiftSettings: [ + .swiftLanguageMode(.v5), + .unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]) + ] + ), .target( name: "JavaKitReflection", dependencies: ["JavaKit", "JavaKitCollection"], @@ -448,6 +462,6 @@ let package = Package( swiftSettings: [ .swiftLanguageMode(.v5) ] - ) + ), ] ) diff --git a/Samples/JavaDependencySampleApp/Package.swift b/Samples/JavaDependencySampleApp/Package.swift index a90cd255..2b5ae361 100644 --- a/Samples/JavaDependencySampleApp/Package.swift +++ b/Samples/JavaDependencySampleApp/Package.swift @@ -86,6 +86,8 @@ let package = Package( .product(name: "JavaKit", package: "swift-java"), .product(name: "JavaKitFunction", package: "swift-java"), .product(name: "JavaKitCollection", package: "swift-java"), + .product(name: "JavaKitIO", package: "swift-java"), + .product(name: "JavaKitNetwork", package: "swift-java"), ], exclude: ["swift-java.config"], swiftSettings: [ @@ -98,5 +100,7 @@ let package = Package( ] ), + .target(name: "JavaExample"), + ] ) diff --git a/Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/swift-java.config b/Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/swift-java.config index 3ab83f79..3b685159 100644 --- a/Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/swift-java.config +++ b/Samples/JavaDependencySampleApp/Sources/JavaCommonsCSV/swift-java.config @@ -1,7 +1,10 @@ { "classes" : { "org.apache.commons.io.FilenameUtils" : "FilenameUtils", - "org.apache.commons.io.IOCase" : "IOCase" + "org.apache.commons.io.IOCase" : "IOCase", + "org.apache.commons.csv.CSVFormat" : "CSVFormat", + "org.apache.commons.csv.CSVParser" : "CSVParser", + "org.apache.commons.csv.CSVRecord" : "CSVRecord" }, "dependencies" : [ "org.apache.commons:commons-csv:1.12.0" diff --git a/Samples/JavaDependencySampleApp/Sources/JavaDependencySample/main.swift b/Samples/JavaDependencySampleApp/Sources/JavaDependencySample/main.swift index 16c2f4a9..c75cf553 100644 --- a/Samples/JavaDependencySampleApp/Sources/JavaDependencySample/main.swift +++ b/Samples/JavaDependencySampleApp/Sources/JavaDependencySample/main.swift @@ -14,6 +14,7 @@ import JavaKit import JavaKitFunction +import JavaKitIO import JavaKitConfigurationShared import Foundation @@ -42,4 +43,13 @@ let ext = try! FilenameUtilsClass.getExtension(path) print("org.apache.commons.io.FilenameUtils.getExtension = \(ext)") precondition(ext == "exe") +let CSVFormatClass = try JavaClass() + +let reader = StringReader("hello,example") +for record in try CSVFormatClass.RFC4180.parse(reader)!.getRecords()! { + for field in record.toList()! { + print("Field: \(field)") + } +} + print("Done.") diff --git a/Samples/JavaDependencySampleApp/Sources/JavaExample/JavaExample.swift b/Samples/JavaDependencySampleApp/Sources/JavaExample/JavaExample.swift new file mode 100644 index 00000000..4724da99 --- /dev/null +++ b/Samples/JavaDependencySampleApp/Sources/JavaExample/JavaExample.swift @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) YEARS Apple Inc. and the Swift.org project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of Swift.org project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// diff --git a/Sources/Java2Swift/JavaToSwift+FetchDependencies.swift b/Sources/Java2Swift/JavaToSwift+FetchDependencies.swift index 9656c310..2a9694c0 100644 --- a/Sources/Java2Swift/JavaToSwift+FetchDependencies.swift +++ b/Sources/Java2Swift/JavaToSwift+FetchDependencies.swift @@ -40,6 +40,10 @@ extension JavaToSwift { print("[info][swift-java] Resolved classpath for \(deps.count) dependencies of '\(moduleName)', classpath entries: \(classpathEntries.count), ", terminator: "") print("done.".green) + for entry in classpathEntries { + print("[info][swift-java] Classpath entry: \(entry)") + } + return ResolvedDependencyClasspath(for: dependencies, classpath: dependenciesClasspath) } @@ -133,6 +137,8 @@ extension JavaToSwift { // The file contents are just plain let contents = resolvedClasspath.classpath + print("[debug][swift-java] Resolved dependency: \(classpath)") + // Write the file try writeContents( contents, diff --git a/Sources/JavaKit/Exceptions/Throwable+Error.swift b/Sources/JavaKit/Exceptions/Throwable+Error.swift index bae53123..fbf8393d 100644 --- a/Sources/JavaKit/Exceptions/Throwable+Error.swift +++ b/Sources/JavaKit/Exceptions/Throwable+Error.swift @@ -15,7 +15,7 @@ // Translate all Java Throwable instances in a Swift error. extension Throwable: Error, CustomStringConvertible { public var description: String { - return getMessage() + return toString() } } diff --git a/Sources/JavaKit/generated/Appendable.swift b/Sources/JavaKit/generated/Appendable.swift new file mode 100644 index 00000000..5c6663f2 --- /dev/null +++ b/Sources/JavaKit/generated/Appendable.swift @@ -0,0 +1,14 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaInterface("java.lang.Appendable") +public struct Appendable { + @JavaMethod + public func append(_ arg0: CharSequence?) throws -> Appendable! + + @JavaMethod + public func append(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32) throws -> Appendable! + + @JavaMethod + public func append(_ arg0: UInt16) throws -> Appendable! +} diff --git a/Sources/JavaKit/generated/CharSequence.swift b/Sources/JavaKit/generated/CharSequence.swift new file mode 100644 index 00000000..cab17273 --- /dev/null +++ b/Sources/JavaKit/generated/CharSequence.swift @@ -0,0 +1,24 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaRuntime + +@JavaInterface("java.lang.CharSequence") +public struct CharSequence { + @JavaMethod + public func length() -> Int32 + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func charAt(_ arg0: Int32) -> UInt16 + + @JavaMethod + public func isEmpty() -> Bool + + @JavaMethod + public func subSequence(_ arg0: Int32, _ arg1: Int32) -> CharSequence! +} +extension JavaClass { + @JavaStaticMethod + public func compare(_ arg0: CharSequence?, _ arg1: CharSequence?) -> Int32 +} diff --git a/Sources/JavaKit/generated/JavaInteger.swift b/Sources/JavaKit/generated/JavaInteger.swift index e5cd5fc1..646aac9e 100644 --- a/Sources/JavaKit/generated/JavaInteger.swift +++ b/Sources/JavaKit/generated/JavaInteger.swift @@ -3,6 +3,7 @@ import JavaRuntime @JavaClass("java.lang.Integer") open class JavaInteger: JavaNumber { + @JavaMethod @_nonoverride public convenience init(_ arg0: Int32, environment: JNIEnvironment? = nil) diff --git a/Sources/JavaKit/generated/JavaLong.swift b/Sources/JavaKit/generated/JavaLong.swift index 491ef1dd..7ff70efa 100644 --- a/Sources/JavaKit/generated/JavaLong.swift +++ b/Sources/JavaKit/generated/JavaLong.swift @@ -167,12 +167,18 @@ extension JavaClass { @JavaStaticMethod public func rotateRight(_ arg0: Int64, _ arg1: Int32) -> Int64 + @JavaStaticMethod + public func parseLong(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32, _ arg3: Int32) throws -> Int64 + @JavaStaticMethod public func parseLong(_ arg0: String, _ arg1: Int32) throws -> Int64 @JavaStaticMethod public func parseLong(_ arg0: String) throws -> Int64 + @JavaStaticMethod + public func parseUnsignedLong(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32, _ arg3: Int32) throws -> Int64 + @JavaStaticMethod public func parseUnsignedLong(_ arg0: String, _ arg1: Int32) throws -> Int64 diff --git a/Sources/JavaKit/generated/JavaString.swift b/Sources/JavaKit/generated/JavaString.swift index 34d0080c..c5f627f2 100644 --- a/Sources/JavaKit/generated/JavaString.swift +++ b/Sources/JavaKit/generated/JavaString.swift @@ -1,7 +1,7 @@ // Auto-generated by Java-to-Swift wrapper generator. import JavaRuntime -@JavaClass("java.lang.String") +@JavaClass("java.lang.String", implements: CharSequence.self) open class JavaString: JavaObject { @JavaMethod @_nonoverride public convenience init(_ arg0: [Int8], _ arg1: String, environment: JNIEnvironment? = nil) throws @@ -52,16 +52,16 @@ open class JavaString: JavaObject { open func getChars(_ arg0: Int32, _ arg1: Int32, _ arg2: [UInt16], _ arg3: Int32) @JavaMethod - open func compareTo(_ arg0: JavaObject?) -> Int32 + open func compareTo(_ arg0: String) -> Int32 @JavaMethod - open func compareTo(_ arg0: String) -> Int32 + open func compareTo(_ arg0: JavaObject?) -> Int32 @JavaMethod - open func indexOf(_ arg0: String, _ arg1: Int32, _ arg2: Int32) -> Int32 + open func indexOf(_ arg0: String, _ arg1: Int32) -> Int32 @JavaMethod - open func indexOf(_ arg0: String) -> Int32 + open func indexOf(_ arg0: String, _ arg1: Int32, _ arg2: Int32) -> Int32 @JavaMethod open func indexOf(_ arg0: Int32) -> Int32 @@ -73,7 +73,7 @@ open class JavaString: JavaObject { open func indexOf(_ arg0: Int32, _ arg1: Int32, _ arg2: Int32) -> Int32 @JavaMethod - open func indexOf(_ arg0: String, _ arg1: Int32) -> Int32 + open func indexOf(_ arg0: String) -> Int32 @JavaMethod open func charAt(_ arg0: Int32) -> UInt16 @@ -90,9 +90,6 @@ open class JavaString: JavaObject { @JavaMethod open func offsetByCodePoints(_ arg0: Int32, _ arg1: Int32) -> Int32 - @JavaMethod - open func getBytes() -> [Int8] - @JavaMethod open func getBytes(_ arg0: String) throws -> [Int8] @@ -100,11 +97,17 @@ open class JavaString: JavaObject { open func getBytes(_ arg0: Int32, _ arg1: Int32, _ arg2: [Int8], _ arg3: Int32) @JavaMethod - open func regionMatches(_ arg0: Bool, _ arg1: Int32, _ arg2: String, _ arg3: Int32, _ arg4: Int32) -> Bool + open func getBytes() -> [Int8] + + @JavaMethod + open func contentEquals(_ arg0: CharSequence?) -> Bool @JavaMethod open func regionMatches(_ arg0: Int32, _ arg1: String, _ arg2: Int32, _ arg3: Int32) -> Bool + @JavaMethod + open func regionMatches(_ arg0: Bool, _ arg1: Int32, _ arg2: String, _ arg3: Int32, _ arg4: Int32) -> Bool + @JavaMethod open func startsWith(_ arg0: String) -> Bool @@ -112,26 +115,29 @@ open class JavaString: JavaObject { open func startsWith(_ arg0: String, _ arg1: Int32) -> Bool @JavaMethod - open func lastIndexOf(_ arg0: String) -> Int32 + open func lastIndexOf(_ arg0: Int32) -> Int32 @JavaMethod - open func lastIndexOf(_ arg0: Int32, _ arg1: Int32) -> Int32 + open func lastIndexOf(_ arg0: String) -> Int32 @JavaMethod open func lastIndexOf(_ arg0: String, _ arg1: Int32) -> Int32 @JavaMethod - open func lastIndexOf(_ arg0: Int32) -> Int32 + open func lastIndexOf(_ arg0: Int32, _ arg1: Int32) -> Int32 @JavaMethod - open func substring(_ arg0: Int32) -> String + open func substring(_ arg0: Int32, _ arg1: Int32) -> String @JavaMethod - open func substring(_ arg0: Int32, _ arg1: Int32) -> String + open func substring(_ arg0: Int32) -> String @JavaMethod open func isEmpty() -> Bool + @JavaMethod + open func replace(_ arg0: CharSequence?, _ arg1: CharSequence?) -> String + @JavaMethod open func replace(_ arg0: UInt16, _ arg1: UInt16) -> String @@ -189,9 +195,15 @@ open class JavaString: JavaObject { @JavaMethod open func endsWith(_ arg0: String) -> Bool + @JavaMethod + open func subSequence(_ arg0: Int32, _ arg1: Int32) -> CharSequence! + @JavaMethod open func concat(_ arg0: String) -> String + @JavaMethod + open func contains(_ arg0: CharSequence?) -> Bool + @JavaMethod open func indent(_ arg0: Int32) -> String @@ -215,39 +227,42 @@ open class JavaString: JavaObject { } } extension JavaClass { + @JavaStaticMethod + public func valueOf(_ arg0: JavaObject?) -> String + @JavaStaticMethod public func valueOf(_ arg0: Int64) -> String @JavaStaticMethod - public func valueOf(_ arg0: [UInt16]) -> String + public func valueOf(_ arg0: Int32) -> String @JavaStaticMethod - public func valueOf(_ arg0: JavaObject?) -> String + public func valueOf(_ arg0: UInt16) -> String @JavaStaticMethod public func valueOf(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) -> String @JavaStaticMethod - public func valueOf(_ arg0: Float) -> String + public func valueOf(_ arg0: Bool) -> String @JavaStaticMethod public func valueOf(_ arg0: Double) -> String @JavaStaticMethod - public func valueOf(_ arg0: UInt16) -> String + public func valueOf(_ arg0: [UInt16]) -> String @JavaStaticMethod - public func valueOf(_ arg0: Bool) -> String + public func valueOf(_ arg0: Float) -> String @JavaStaticMethod - public func valueOf(_ arg0: Int32) -> String + public func join(_ arg0: CharSequence?, _ arg1: [CharSequence?]) -> String @JavaStaticMethod public func format(_ arg0: String, _ arg1: [JavaObject?]) -> String @JavaStaticMethod - public func copyValueOf(_ arg0: [UInt16]) -> String + public func copyValueOf(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) -> String @JavaStaticMethod - public func copyValueOf(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) -> String + public func copyValueOf(_ arg0: [UInt16]) -> String } diff --git a/Sources/JavaKit/swift-java.config b/Sources/JavaKit/swift-java.config index 34751edd..b45671a7 100644 --- a/Sources/JavaKit/swift-java.config +++ b/Sources/JavaKit/swift-java.config @@ -19,6 +19,8 @@ "java.lang.String" : "JavaString", "java.lang.Throwable" : "Throwable", "java.lang.Void" : "JavaVoid", + "java.lang.CharSequence": "CharSequence", + "java.lang.Appendable": "Appendable", "java.util.Optional": "JavaOptional", "java.util.OptionalDouble": "JavaOptionalDouble", "java.util.OptionalInt": "JavaOptionalInt", diff --git a/Sources/JavaKitCollection/generated/BitSet.swift b/Sources/JavaKitCollection/generated/BitSet.swift index c7e54b95..d5211c28 100644 --- a/Sources/JavaKitCollection/generated/BitSet.swift +++ b/Sources/JavaKitCollection/generated/BitSet.swift @@ -4,38 +4,20 @@ import JavaRuntime @JavaClass("java.util.BitSet") open class BitSet: JavaObject { - @JavaMethod - @_nonoverride public convenience init(environment: JNIEnvironment? = nil) - @JavaMethod @_nonoverride public convenience init(_ arg0: Int32, environment: JNIEnvironment? = nil) @JavaMethod - open func cardinality() -> Int32 - - @JavaMethod - open func nextSetBit(_ arg0: Int32) -> Int32 - - @JavaMethod - open func toLongArray() -> [Int64] - - @JavaMethod - open func previousSetBit(_ arg0: Int32) -> Int32 - - @JavaMethod - open func previousClearBit(_ arg0: Int32) -> Int32 - - @JavaMethod - open func intersects(_ arg0: BitSet?) -> Bool + @_nonoverride public convenience init(environment: JNIEnvironment? = nil) @JavaMethod open func size() -> Int32 @JavaMethod - open func get(_ arg0: Int32, _ arg1: Int32) -> BitSet! + open func get(_ arg0: Int32) -> Bool @JavaMethod - open func get(_ arg0: Int32) -> Bool + open func get(_ arg0: Int32, _ arg1: Int32) -> BitSet! @JavaMethod open override func equals(_ arg0: JavaObject?) -> Bool @@ -52,9 +34,6 @@ open class BitSet: JavaObject { @JavaMethod open override func clone() -> JavaObject! - @JavaMethod - open func clear(_ arg0: Int32) - @JavaMethod open func clear(_ arg0: Int32, _ arg1: Int32) @@ -62,19 +41,22 @@ open class BitSet: JavaObject { open func clear() @JavaMethod - open func isEmpty() -> Bool + open func clear(_ arg0: Int32) @JavaMethod - open func set(_ arg0: Int32, _ arg1: Int32, _ arg2: Bool) + open func isEmpty() -> Bool @JavaMethod - open func set(_ arg0: Int32, _ arg1: Int32) + open func set(_ arg0: Int32, _ arg1: Bool) @JavaMethod open func set(_ arg0: Int32) @JavaMethod - open func set(_ arg0: Int32, _ arg1: Bool) + open func set(_ arg0: Int32, _ arg1: Int32) + + @JavaMethod + open func set(_ arg0: Int32, _ arg1: Int32, _ arg2: Bool) @JavaMethod open func flip(_ arg0: Int32, _ arg1: Int32) @@ -99,6 +81,24 @@ open class BitSet: JavaObject { @JavaMethod open func andNot(_ arg0: BitSet?) + + @JavaMethod + open func cardinality() -> Int32 + + @JavaMethod + open func nextSetBit(_ arg0: Int32) -> Int32 + + @JavaMethod + open func toLongArray() -> [Int64] + + @JavaMethod + open func previousSetBit(_ arg0: Int32) -> Int32 + + @JavaMethod + open func previousClearBit(_ arg0: Int32) -> Int32 + + @JavaMethod + open func intersects(_ arg0: BitSet?) -> Bool } extension JavaClass { @JavaStaticMethod diff --git a/Sources/JavaKitCollection/generated/HashMap.swift b/Sources/JavaKitCollection/generated/HashMap.swift index e8cfa118..424dfbb9 100644 --- a/Sources/JavaKitCollection/generated/HashMap.swift +++ b/Sources/JavaKitCollection/generated/HashMap.swift @@ -61,56 +61,6 @@ open class HashMap: JavaObject { @JavaMethod open func getOrDefault(_ arg0: JavaObject?, _ arg1: JavaObject?) -> JavaObject! } -extension HashMap { - @JavaClass("java.util.AbstractMap$SimpleEntry") - open class SimpleEntry: JavaObject { - @JavaMethod - @_nonoverride public convenience init(_ arg0: JavaObject?, _ arg1: JavaObject?, environment: JNIEnvironment? = nil) - - @JavaMethod - open override func equals(_ arg0: JavaObject?) -> Bool - - @JavaMethod - open override func toString() -> String - - @JavaMethod - open override func hashCode() -> Int32 - - @JavaMethod - open func getValue() -> JavaObject! - - @JavaMethod - open func getKey() -> JavaObject! - - @JavaMethod - open func setValue(_ arg0: JavaObject?) -> JavaObject! - } -} -extension HashMap { - @JavaClass("java.util.AbstractMap$SimpleImmutableEntry") - open class SimpleImmutableEntry: JavaObject { - @JavaMethod - @_nonoverride public convenience init(_ arg0: JavaObject?, _ arg1: JavaObject?, environment: JNIEnvironment? = nil) - - @JavaMethod - open override func equals(_ arg0: JavaObject?) -> Bool - - @JavaMethod - open override func toString() -> String - - @JavaMethod - open override func hashCode() -> Int32 - - @JavaMethod - open func getValue() -> JavaObject! - - @JavaMethod - open func getKey() -> JavaObject! - - @JavaMethod - open func setValue(_ arg0: JavaObject?) -> JavaObject! - } -} extension JavaClass { @JavaStaticMethod public func newHashMap(_ arg0: Int32) -> HashMap! where ObjectType == HashMap diff --git a/Sources/JavaKitCollection/generated/TreeMap.swift b/Sources/JavaKitCollection/generated/TreeMap.swift index 79560905..7796d555 100644 --- a/Sources/JavaKitCollection/generated/TreeMap.swift +++ b/Sources/JavaKitCollection/generated/TreeMap.swift @@ -70,3 +70,53 @@ open class TreeMap: JavaObject { @JavaMethod open func lastKey() -> JavaObject! } +extension TreeMap { + @JavaClass("java.util.AbstractMap$SimpleEntry") + open class SimpleEntry: JavaObject { + @JavaMethod + @_nonoverride public convenience init(_ arg0: JavaObject?, _ arg1: JavaObject?, environment: JNIEnvironment? = nil) + + @JavaMethod + open override func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + open override func toString() -> String + + @JavaMethod + open override func hashCode() -> Int32 + + @JavaMethod + open func getValue() -> JavaObject! + + @JavaMethod + open func getKey() -> JavaObject! + + @JavaMethod + open func setValue(_ arg0: JavaObject?) -> JavaObject! + } +} +extension TreeMap { + @JavaClass("java.util.AbstractMap$SimpleImmutableEntry") + open class SimpleImmutableEntry: JavaObject { + @JavaMethod + @_nonoverride public convenience init(_ arg0: JavaObject?, _ arg1: JavaObject?, environment: JNIEnvironment? = nil) + + @JavaMethod + open override func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + open override func toString() -> String + + @JavaMethod + open override func hashCode() -> Int32 + + @JavaMethod + open func getValue() -> JavaObject! + + @JavaMethod + open func getKey() -> JavaObject! + + @JavaMethod + open func setValue(_ arg0: JavaObject?) -> JavaObject! + } +} diff --git a/Sources/JavaKitIO/generated/BufferedInputStream.swift b/Sources/JavaKitIO/generated/BufferedInputStream.swift new file mode 100644 index 00000000..8ea95eeb --- /dev/null +++ b/Sources/JavaKitIO/generated/BufferedInputStream.swift @@ -0,0 +1,39 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.BufferedInputStream") +open class BufferedInputStream: InputStream { + @JavaMethod + @_nonoverride public convenience init(_ arg0: InputStream?, environment: JNIEnvironment? = nil) + + @JavaMethod + @_nonoverride public convenience init(_ arg0: InputStream?, _ arg1: Int32, environment: JNIEnvironment? = nil) + + @JavaMethod + open override func reset() throws + + @JavaMethod + open override func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32 + + @JavaMethod + open override func read() throws -> Int32 + + @JavaMethod + open override func close() throws + + @JavaMethod + open override func mark(_ arg0: Int32) + + @JavaMethod + open override func transferTo(_ arg0: OutputStream?) throws -> Int64 + + @JavaMethod + open override func skip(_ arg0: Int64) throws -> Int64 + + @JavaMethod + open override func available() throws -> Int32 + + @JavaMethod + open override func markSupported() -> Bool +} diff --git a/Sources/JavaKitIO/generated/Charset.swift b/Sources/JavaKitIO/generated/Charset.swift new file mode 100644 index 00000000..fda054ef --- /dev/null +++ b/Sources/JavaKitIO/generated/Charset.swift @@ -0,0 +1,49 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.nio.charset.Charset") +open class Charset: JavaObject { + @JavaMethod + open func name() -> String + + @JavaMethod + open override func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + open override func toString() -> String + + @JavaMethod + open override func hashCode() -> Int32 + + @JavaMethod + open func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + open func compareTo(_ arg0: Charset?) -> Int32 + + @JavaMethod + open func canEncode() -> Bool + + @JavaMethod + open func contains(_ arg0: Charset?) -> Bool + + @JavaMethod + open func isRegistered() -> Bool + + @JavaMethod + open func displayName() -> String +} +extension JavaClass { + @JavaStaticMethod + public func forName(_ arg0: String, _ arg1: Charset?) -> Charset! + + @JavaStaticMethod + public func forName(_ arg0: String) -> Charset! + + @JavaStaticMethod + public func defaultCharset() -> Charset! + + @JavaStaticMethod + public func isSupported(_ arg0: String) -> Bool +} diff --git a/Sources/JavaKitIO/generated/Closeable.swift b/Sources/JavaKitIO/generated/Closeable.swift new file mode 100644 index 00000000..6da8e2a9 --- /dev/null +++ b/Sources/JavaKitIO/generated/Closeable.swift @@ -0,0 +1,9 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaInterface("java.io.Closeable") +public struct Closeable { + @JavaMethod + public func close() throws +} diff --git a/Sources/JavaKitIO/generated/File.swift b/Sources/JavaKitIO/generated/File.swift new file mode 100644 index 00000000..5cbdb70e --- /dev/null +++ b/Sources/JavaKitIO/generated/File.swift @@ -0,0 +1,166 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.File") +open class File: JavaObject { + @JavaMethod + @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) + + @JavaMethod + @_nonoverride public convenience init(_ arg0: String, _ arg1: String, environment: JNIEnvironment? = nil) + + @JavaMethod + @_nonoverride public convenience init(_ arg0: File?, _ arg1: String, environment: JNIEnvironment? = nil) + + @JavaMethod + open func getName() -> String + + @JavaMethod + open override func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + open func length() -> Int64 + + @JavaMethod + open override func toString() -> String + + @JavaMethod + open override func hashCode() -> Int32 + + @JavaMethod + open func isHidden() -> Bool + + @JavaMethod + open func compareTo(_ arg0: File?) -> Int32 + + @JavaMethod + open func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + open func list() -> [String] + + @JavaMethod + open func isAbsolute() -> Bool + + @JavaMethod + open func getParent() -> String + + @JavaMethod + open func delete() -> Bool + + @JavaMethod + open func setReadOnly() -> Bool + + @JavaMethod + open func canRead() -> Bool + + @JavaMethod + open func getPath() -> String + + @JavaMethod + open func getAbsolutePath() -> String + + @JavaMethod + open func exists() -> Bool + + @JavaMethod + open func createNewFile() throws -> Bool + + @JavaMethod + open func renameTo(_ arg0: File?) -> Bool + + @JavaMethod + open func isDirectory() -> Bool + + @JavaMethod + open func getCanonicalPath() throws -> String + + @JavaMethod + open func getAbsoluteFile() -> File! + + @JavaMethod + open func mkdir() -> Bool + + @JavaMethod + open func getCanonicalFile() throws -> File! + + @JavaMethod + open func getParentFile() -> File! + + @JavaMethod + open func mkdirs() -> Bool + + @JavaMethod + open func setWritable(_ arg0: Bool) -> Bool + + @JavaMethod + open func setWritable(_ arg0: Bool, _ arg1: Bool) -> Bool + + @JavaMethod + open func setReadable(_ arg0: Bool, _ arg1: Bool) -> Bool + + @JavaMethod + open func setReadable(_ arg0: Bool) -> Bool + + @JavaMethod + open func setExecutable(_ arg0: Bool, _ arg1: Bool) -> Bool + + @JavaMethod + open func setExecutable(_ arg0: Bool) -> Bool + + @JavaMethod + open func canWrite() -> Bool + + @JavaMethod + open func isFile() -> Bool + + @JavaMethod + open func lastModified() -> Int64 + + @JavaMethod + open func deleteOnExit() + + @JavaMethod + open func listFiles() -> [File?] + + @JavaMethod + open func setLastModified(_ arg0: Int64) -> Bool + + @JavaMethod + open func canExecute() -> Bool + + @JavaMethod + open func getTotalSpace() -> Int64 + + @JavaMethod + open func getFreeSpace() -> Int64 + + @JavaMethod + open func getUsableSpace() -> Int64 + + @JavaMethod + open func toPath() -> Path! +} +extension JavaClass { + @JavaStaticField(isFinal: true) + public var separatorChar: UInt16 + + @JavaStaticField(isFinal: true) + public var separator: String + + @JavaStaticField(isFinal: true) + public var pathSeparatorChar: UInt16 + + @JavaStaticField(isFinal: true) + public var pathSeparator: String + + @JavaStaticMethod + public func listRoots() -> [File?] + + @JavaStaticMethod + public func createTempFile(_ arg0: String, _ arg1: String) throws -> File! + + @JavaStaticMethod + public func createTempFile(_ arg0: String, _ arg1: String, _ arg2: File?) throws -> File! +} diff --git a/Sources/JavaKitIO/generated/FileDescriptor.swift b/Sources/JavaKitIO/generated/FileDescriptor.swift new file mode 100644 index 00000000..81490e46 --- /dev/null +++ b/Sources/JavaKitIO/generated/FileDescriptor.swift @@ -0,0 +1,25 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.FileDescriptor") +open class FileDescriptor: JavaObject { + @JavaMethod + @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + + @JavaMethod + open func sync() throws + + @JavaMethod + open func valid() -> Bool +} +extension JavaClass { + @JavaStaticField(isFinal: true) + public var `in`: FileDescriptor! + + @JavaStaticField(isFinal: true) + public var out: FileDescriptor! + + @JavaStaticField(isFinal: true) + public var err: FileDescriptor! +} diff --git a/Sources/JavaKitIO/generated/FileReader.swift b/Sources/JavaKitIO/generated/FileReader.swift new file mode 100644 index 00000000..5254bdd0 --- /dev/null +++ b/Sources/JavaKitIO/generated/FileReader.swift @@ -0,0 +1,21 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.FileReader") +open class FileReader: InputStreamReader { + @JavaMethod + @_nonoverride public convenience init(_ arg0: File?, _ arg1: Charset?, environment: JNIEnvironment? = nil) throws + + @JavaMethod + @_nonoverride public convenience init(_ arg0: String, _ arg1: Charset?, environment: JNIEnvironment? = nil) throws + + @JavaMethod + @_nonoverride public convenience init(_ arg0: FileDescriptor?, environment: JNIEnvironment? = nil) + + @JavaMethod + @_nonoverride public convenience init(_ arg0: File?, environment: JNIEnvironment? = nil) throws + + @JavaMethod + @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) throws +} diff --git a/Sources/JavaKitIO/generated/Flushable.swift b/Sources/JavaKitIO/generated/Flushable.swift new file mode 100644 index 00000000..daf621f6 --- /dev/null +++ b/Sources/JavaKitIO/generated/Flushable.swift @@ -0,0 +1,9 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaInterface("java.io.Flushable") +public struct Flushable { + @JavaMethod + public func flush() throws +} diff --git a/Sources/JavaKitIO/generated/InputStream.swift b/Sources/JavaKitIO/generated/InputStream.swift new file mode 100644 index 00000000..971a610b --- /dev/null +++ b/Sources/JavaKitIO/generated/InputStream.swift @@ -0,0 +1,55 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.InputStream", implements: Closeable.self) +open class InputStream: JavaObject { + @JavaMethod + @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + + @JavaMethod + open func reset() throws + + @JavaMethod + open func read(_ arg0: [Int8]) throws -> Int32 + + @JavaMethod + open func read(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32 + + @JavaMethod + open func read() throws -> Int32 + + @JavaMethod + open func close() throws + + @JavaMethod + open func readAllBytes() throws -> [Int8] + + @JavaMethod + open func mark(_ arg0: Int32) + + @JavaMethod + open func readNBytes(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws -> Int32 + + @JavaMethod + open func readNBytes(_ arg0: Int32) throws -> [Int8] + + @JavaMethod + open func transferTo(_ arg0: OutputStream?) throws -> Int64 + + @JavaMethod + open func skip(_ arg0: Int64) throws -> Int64 + + @JavaMethod + open func available() throws -> Int32 + + @JavaMethod + open func markSupported() -> Bool + + @JavaMethod + open func skipNBytes(_ arg0: Int64) throws +} +extension JavaClass { + @JavaStaticMethod + public func nullInputStream() -> InputStream! +} diff --git a/Sources/JavaKitIO/generated/InputStreamReader.swift b/Sources/JavaKitIO/generated/InputStreamReader.swift new file mode 100644 index 00000000..2766aeba --- /dev/null +++ b/Sources/JavaKitIO/generated/InputStreamReader.swift @@ -0,0 +1,30 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.InputStreamReader") +open class InputStreamReader: Reader { + @JavaMethod + @_nonoverride public convenience init(_ arg0: InputStream?, _ arg1: Charset?, environment: JNIEnvironment? = nil) + + @JavaMethod + @_nonoverride public convenience init(_ arg0: InputStream?, _ arg1: String, environment: JNIEnvironment? = nil) throws + + @JavaMethod + @_nonoverride public convenience init(_ arg0: InputStream?, environment: JNIEnvironment? = nil) + + @JavaMethod + open override func ready() throws -> Bool + + @JavaMethod + open override func read() throws -> Int32 + + @JavaMethod + open override func read(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws -> Int32 + + @JavaMethod + open override func close() throws + + @JavaMethod + open func getEncoding() -> String +} diff --git a/Sources/JavaKitIO/generated/OutputStream.swift b/Sources/JavaKitIO/generated/OutputStream.swift new file mode 100644 index 00000000..e169bfd0 --- /dev/null +++ b/Sources/JavaKitIO/generated/OutputStream.swift @@ -0,0 +1,28 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.OutputStream", implements: Closeable.self, Flushable.self) +open class OutputStream: JavaObject { + @JavaMethod + @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + + @JavaMethod + open func flush() throws + + @JavaMethod + open func write(_ arg0: [Int8]) throws + + @JavaMethod + open func write(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32) throws + + @JavaMethod + open func write(_ arg0: Int32) throws + + @JavaMethod + open func close() throws +} +extension JavaClass { + @JavaStaticMethod + public func nullOutputStream() -> OutputStream! +} diff --git a/Sources/JavaKitIO/generated/Path.swift b/Sources/JavaKitIO/generated/Path.swift new file mode 100644 index 00000000..e93d0381 --- /dev/null +++ b/Sources/JavaKitIO/generated/Path.swift @@ -0,0 +1,88 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaInterface("java.nio.file.Path") +public struct Path { + @JavaMethod + public func getName(_ arg0: Int32) -> Path! + + @JavaMethod + public func equals(_ arg0: JavaObject?) -> Bool + + @JavaMethod + public func toString() -> String + + @JavaMethod + public func hashCode() -> Int32 + + @JavaMethod + public func compareTo(_ arg0: Path?) -> Int32 + + @JavaMethod + public func compareTo(_ arg0: JavaObject?) -> Int32 + + @JavaMethod + public func startsWith(_ arg0: String) -> Bool + + @JavaMethod + public func startsWith(_ arg0: Path?) -> Bool + + @JavaMethod + public func endsWith(_ arg0: String) -> Bool + + @JavaMethod + public func endsWith(_ arg0: Path?) -> Bool + + @JavaMethod + public func isAbsolute() -> Bool + + @JavaMethod + public func resolve(_ arg0: String, _ arg1: [String]) -> Path! + + @JavaMethod + public func resolve(_ arg0: Path?, _ arg1: [Path?]) -> Path! + + @JavaMethod + public func resolve(_ arg0: String) -> Path! + + @JavaMethod + public func resolve(_ arg0: Path?) -> Path! + + @JavaMethod + public func getParent() -> Path! + + @JavaMethod + public func getRoot() -> Path! + + @JavaMethod + public func toFile() -> File! + + @JavaMethod + public func getFileName() -> Path! + + @JavaMethod + public func normalize() -> Path! + + @JavaMethod + public func relativize(_ arg0: Path?) -> Path! + + @JavaMethod + public func getNameCount() -> Int32 + + @JavaMethod + public func toAbsolutePath() -> Path! + + @JavaMethod + public func resolveSibling(_ arg0: String) -> Path! + + @JavaMethod + public func resolveSibling(_ arg0: Path?) -> Path! + + @JavaMethod + public func subpath(_ arg0: Int32, _ arg1: Int32) -> Path! +} +extension JavaClass { + @JavaStaticMethod + public func of(_ arg0: String, _ arg1: [String]) -> Path! +} diff --git a/Sources/JavaKitIO/generated/Readable.swift b/Sources/JavaKitIO/generated/Readable.swift new file mode 100644 index 00000000..16825989 --- /dev/null +++ b/Sources/JavaKitIO/generated/Readable.swift @@ -0,0 +1,8 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaInterface("java.lang.Readable") +public struct Readable { + +} diff --git a/Sources/JavaKitIO/generated/Reader.swift b/Sources/JavaKitIO/generated/Reader.swift new file mode 100644 index 00000000..2f6cdfe2 --- /dev/null +++ b/Sources/JavaKitIO/generated/Reader.swift @@ -0,0 +1,40 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.Reader", implements: Readable.self, Closeable.self) +open class Reader: JavaObject { + @JavaMethod + open func ready() throws -> Bool + + @JavaMethod + open func reset() throws + + @JavaMethod + open func read(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws -> Int32 + + @JavaMethod + open func read() throws -> Int32 + + @JavaMethod + open func read(_ arg0: [UInt16]) throws -> Int32 + + @JavaMethod + open func close() throws + + @JavaMethod + open func mark(_ arg0: Int32) throws + + @JavaMethod + open func transferTo(_ arg0: Writer?) throws -> Int64 + + @JavaMethod + open func skip(_ arg0: Int64) throws -> Int64 + + @JavaMethod + open func markSupported() -> Bool +} +extension JavaClass { + @JavaStaticMethod + public func nullReader() -> Reader! +} diff --git a/Sources/JavaKitIO/generated/StringReader.swift b/Sources/JavaKitIO/generated/StringReader.swift new file mode 100644 index 00000000..e2af1166 --- /dev/null +++ b/Sources/JavaKitIO/generated/StringReader.swift @@ -0,0 +1,33 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.StringReader") +open class StringReader: Reader { + @JavaMethod + @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) + + @JavaMethod + open override func ready() throws -> Bool + + @JavaMethod + open override func reset() throws + + @JavaMethod + open override func read() throws -> Int32 + + @JavaMethod + open override func read(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws -> Int32 + + @JavaMethod + open override func close() + + @JavaMethod + open override func mark(_ arg0: Int32) throws + + @JavaMethod + open override func skip(_ arg0: Int64) throws -> Int64 + + @JavaMethod + open override func markSupported() -> Bool +} diff --git a/Sources/JavaKitIO/generated/WatchService.swift b/Sources/JavaKitIO/generated/WatchService.swift new file mode 100644 index 00000000..20bca06f --- /dev/null +++ b/Sources/JavaKitIO/generated/WatchService.swift @@ -0,0 +1,9 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaInterface("java.nio.file.WatchService", extends: Closeable.self) +public struct WatchService { + @JavaMethod + public func close() throws +} diff --git a/Sources/JavaKitIO/generated/Writer.swift b/Sources/JavaKitIO/generated/Writer.swift new file mode 100644 index 00000000..5e3fdff2 --- /dev/null +++ b/Sources/JavaKitIO/generated/Writer.swift @@ -0,0 +1,49 @@ +// Auto-generated by Java-to-Swift wrapper generator. +import JavaKit +import JavaRuntime + +@JavaClass("java.io.Writer", implements: Appendable.self, Closeable.self, Flushable.self) +open class Writer: JavaObject { + @JavaMethod + open func append(_ arg0: UInt16) throws -> Writer! + + @JavaMethod + open func append(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32) throws -> Writer! + + @JavaMethod + open func append(_ arg0: CharSequence?) throws -> Writer! + + @JavaMethod + open func append(_ arg0: CharSequence?) throws -> Appendable! + + @JavaMethod + open func append(_ arg0: UInt16) throws -> Appendable! + + @JavaMethod + open func append(_ arg0: CharSequence?, _ arg1: Int32, _ arg2: Int32) throws -> Appendable! + + @JavaMethod + open func flush() throws + + @JavaMethod + open func write(_ arg0: Int32) throws + + @JavaMethod + open func write(_ arg0: [UInt16], _ arg1: Int32, _ arg2: Int32) throws + + @JavaMethod + open func write(_ arg0: String) throws + + @JavaMethod + open func write(_ arg0: String, _ arg1: Int32, _ arg2: Int32) throws + + @JavaMethod + open func write(_ arg0: [UInt16]) throws + + @JavaMethod + open func close() throws +} +extension JavaClass { + @JavaStaticMethod + public func nullWriter() -> Writer! +} diff --git a/Sources/JavaKitIO/swift-java.config b/Sources/JavaKitIO/swift-java.config new file mode 100644 index 00000000..7b40b2da --- /dev/null +++ b/Sources/JavaKitIO/swift-java.config @@ -0,0 +1,21 @@ +{ + "classes" : { + "java.io.FileReader" : "FileReader", + "java.io.StringReader" : "StringReader", + "java.io.InputStreamReader" : "InputStreamReader", + "java.io.BufferedInputStream" : "BufferedInputStream", + "java.io.InputStream" : "InputStream", + "java.io.OutputStream" : "OutputStream", + "java.io.Reader" : "Reader", + "java.lang.Readable" : "Readable", + "java.io.Writer" : "Writer", + "java.io.File" : "File", + "java.nio.file.Path" : "Path", + "java.io.FileDescriptor" : "FileDescriptor", + "java.nio.charset.Charset" : "Charset", + "java.io.Closeable" : "Closeable", + "java.io.Flushable" : "Flushable", + "java.io.Flushable" : "ByteBuffer", + "java.nio.file.WatchService" : "WatchService", + } +} diff --git a/Tests/JavaKitTests/BasicRuntimeTests.swift b/Tests/JavaKitTests/BasicRuntimeTests.swift index 1cb0e787..d42fa4b1 100644 --- a/Tests/JavaKitTests/BasicRuntimeTests.swift +++ b/Tests/JavaKitTests/BasicRuntimeTests.swift @@ -56,7 +56,7 @@ class BasicRuntimeTests: XCTestCase { do { _ = try URL("bad url", environment: environment) } catch { - XCTAssert(String(describing: error) == "no protocol: bad url") + XCTAssertEqual(String(describing: error), "java.net.MalformedURLException: no protocol: bad url") } } @@ -73,7 +73,7 @@ class BasicRuntimeTests: XCTestCase { do { _ = try JavaClass(environment: environment) } catch { - XCTAssertEqual(String(describing: error), "org/swift/javakit/Nonexistent") + XCTAssertEqual(String(describing: error), "java.lang.NoClassDefFoundError: org/swift/javakit/Nonexistent") } }