Skip to content

Commit cbe7e76

Browse files
authored
Merge pull request #1735 from pedroSG94/feature/java-io
Feature/java io
2 parents 1c5482d + ad2e898 commit cbe7e76

File tree

82 files changed

+750
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+750
-667
lines changed

common/src/main/java/com/pedro/common/Extensions.kt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import androidx.annotation.RequiresApi
2727
import com.pedro.common.frame.MediaFrame
2828
import kotlinx.coroutines.Dispatchers
2929
import kotlinx.coroutines.withContext
30+
import java.io.InputStream
31+
import java.io.OutputStream
3032
import java.io.UnsupportedEncodingException
3133
import java.nio.ByteBuffer
3234
import java.security.MessageDigest
@@ -153,4 +155,78 @@ fun MediaFormat.getIntegerSafe(name: String): Int? {
153155

154156
fun MediaFormat.getLongSafe(name: String): Long? {
155157
return try { getLong(name) } catch (e: Exception) { null }
158+
}
159+
160+
fun Int.toUInt16(): ByteArray = byteArrayOf((this ushr 8).toByte(), this.toByte())
161+
162+
fun Int.toUInt24(): ByteArray {
163+
return byteArrayOf((this ushr 16).toByte(), (this ushr 8).toByte(), this.toByte())
164+
}
165+
166+
fun Int.toUInt32(): ByteArray {
167+
return byteArrayOf((this ushr 24).toByte(), (this ushr 16).toByte(), (this ushr 8).toByte(), this.toByte())
168+
}
169+
170+
fun Int.toUInt32LittleEndian(): ByteArray = Integer.reverseBytes(this).toUInt32()
171+
172+
fun ByteArray.toUInt16(): Int {
173+
return this[0].toInt() and 0xff shl 8 or (this[1].toInt() and 0xff)
174+
}
175+
176+
fun ByteArray.toUInt24(): Int {
177+
return this[0].toInt() and 0xff shl 16 or (this[1].toInt() and 0xff shl 8) or (this[2].toInt() and 0xff)
178+
}
179+
180+
fun ByteArray.toUInt32(): Int {
181+
return this[0].toInt() and 0xff shl 24 or (this[1].toInt() and 0xff shl 16) or (this[2].toInt() and 0xff shl 8) or (this[3].toInt() and 0xff)
182+
}
183+
184+
fun ByteArray.toUInt32LittleEndian(): Int {
185+
return Integer.reverseBytes(toUInt32())
186+
}
187+
188+
fun InputStream.readUntil(byteArray: ByteArray) {
189+
var bytesRead = 0
190+
while (bytesRead < byteArray.size) {
191+
val result = read(byteArray, bytesRead, byteArray.size - bytesRead)
192+
if (result != -1) bytesRead += result
193+
}
194+
}
195+
196+
fun InputStream.readUInt32(): Int {
197+
val data = ByteArray(4)
198+
read(data)
199+
return data.toUInt32()
200+
}
201+
202+
fun InputStream.readUInt24(): Int {
203+
val data = ByteArray(3)
204+
read(data)
205+
return data.toUInt24()
206+
}
207+
208+
fun InputStream.readUInt16(): Int {
209+
val data = ByteArray(2)
210+
read(data)
211+
return data.toUInt16()
212+
}
213+
214+
fun InputStream.readUInt32LittleEndian(): Int {
215+
return Integer.reverseBytes(readUInt32())
216+
}
217+
218+
fun OutputStream.writeUInt32(value: Int) {
219+
write(value.toUInt32())
220+
}
221+
222+
fun OutputStream.writeUInt24(value: Int) {
223+
write(value.toUInt24())
224+
}
225+
226+
fun OutputStream.writeUInt16(value: Int) {
227+
write(value.toUInt16())
228+
}
229+
230+
fun OutputStream.writeUInt32LittleEndian(value: Int) {
231+
write(value.toUInt32LittleEndian())
156232
}

common/src/main/java/com/pedro/common/TLSSocketFactory.kt

Lines changed: 0 additions & 89 deletions
This file was deleted.

common/src/main/java/com/pedro/common/socket/StreamSocket.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

common/src/main/java/com/pedro/common/socket/TcpStreamSocket.kt

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)