mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-26 00:52:07 +01:00
Kotlin conversion: ByteArrayAndResult
This commit is contained in:
parent
4bd4657906
commit
0f5270c28d
2 changed files with 43 additions and 50 deletions
|
@ -1,50 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Tuple of a byte array and associated result object.
|
||||
* @param <T> type of result
|
||||
*/
|
||||
public class ByteArrayAndResult<T> {
|
||||
|
||||
private final byte[] bytes;
|
||||
private final T result;
|
||||
|
||||
public ByteArrayAndResult(byte[] bytes, T result) {
|
||||
this.bytes = bytes;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the byte array part.
|
||||
*
|
||||
* @return bytes
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result part.
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the byte array part as an {@link InputStream}.
|
||||
*
|
||||
* @return input stream
|
||||
*/
|
||||
public InputStream getInputStream() {
|
||||
return new ByteArrayInputStream(getBytes());
|
||||
}
|
||||
}
|
43
sop-java/src/main/kotlin/sop/ByteArrayAndResult.kt
Normal file
43
sop-java/src/main/kotlin/sop/ByteArrayAndResult.kt
Normal file
|
@ -0,0 +1,43 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Tuple of a [ByteArray] and associated result object.
|
||||
*
|
||||
* @param bytes byte array
|
||||
* @param result result object
|
||||
* @param <T> type of result
|
||||
*/
|
||||
data class ByteArrayAndResult<T>(val bytes: ByteArray, val result: T) {
|
||||
|
||||
/**
|
||||
* [InputStream] returning the contents of [bytes].
|
||||
*
|
||||
* @return input stream
|
||||
*/
|
||||
val inputStream: InputStream
|
||||
get() = bytes.inputStream()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as ByteArrayAndResult<*>
|
||||
|
||||
if (!bytes.contentEquals(other.bytes)) return false
|
||||
if (result != other.result) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var hashCode = bytes.contentHashCode()
|
||||
hashCode = 31 * hashCode + (result?.hashCode() ?: 0)
|
||||
return hashCode
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue