generated from korlibs/korlibs-library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve InputOutputStream interoperability and deprecate redundant me…
…thod (#2)
- Loading branch information
Showing
5 changed files
with
47 additions
and
24 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,27 +1,38 @@ | ||
package korlibs.io.stream | ||
|
||
import java.io.InputStream | ||
import java.io.OutputStream | ||
import java.io.* | ||
|
||
fun InputStream.toSyncInputStream(): SyncInputStream { | ||
return object : SyncInputStream { | ||
override fun read(buffer: ByteArray, offset: Int, len: Int): Int { | ||
//println("READ[s]: $len") | ||
return this@toSyncInputStream.read(buffer, offset, len).also { | ||
//println("READ[e]: $len") | ||
} | ||
override fun read(buffer: ByteArray, offset: Int, len: Int): Int = this@toSyncInputStream.read(buffer, offset, len) | ||
|
||
override fun read(): Int = this@toSyncInputStream.read() | ||
|
||
override fun skip(count: Int) { | ||
this@toSyncInputStream.skip(count.toLong()) | ||
} | ||
|
||
override fun close() { | ||
this@toSyncInputStream.close() | ||
} | ||
} | ||
} | ||
|
||
fun OutputStream.toSyncOutputStream(): SyncOutputStream { | ||
return object : SyncOutputStream { | ||
override fun write(byte: Int) { | ||
this@toSyncOutputStream.write(byte) | ||
} | ||
|
||
override fun write(buffer: ByteArray, offset: Int, len: Int) { | ||
//println("WRITE[s]: $len") | ||
return this@toSyncOutputStream.write(buffer, offset, len).also { | ||
this@toSyncOutputStream.flush() | ||
//println("WRITE[e]: $len") | ||
} | ||
} | ||
|
||
override fun flush() = this@toSyncOutputStream.flush() | ||
override fun close() = this@toSyncOutputStream.close() | ||
} | ||
} |
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