Changeset View
Changeset View
Standalone View
Standalone View
src/main/java/net/wildfyre/http/Request.kt
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | private fun multipart(conn: HttpURLConnection) { | ||||
} | } | ||||
}) | }) | ||||
writer.write(endl) | writer.write(endl) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Throw NullPointerException if fileOutput is null | // Throw NullPointerException if fileOutput is null (see end of let scope) | ||||
fileOutput?.let { file -> | fileOutput?.let { file -> | ||||
writer.write(hyphens + boundary + endl) | writer.write(hyphens + boundary + endl) | ||||
writer.write("Content-Disposition: form-data; name=\"$fileOutputName\"; filename=\"${file.name}\"$endl") | writer.write("Content-Disposition: form-data; name=\"$fileOutputName\"; filename=\"${file.name}\"$endl") | ||||
writer.write("Content-Type: ${URLConnection.guessContentTypeFromName(file.name)}" + endl) | writer.write("Content-Type: ${URLConnection.guessContentTypeFromName(file.name)}" + endl) | ||||
writer.write(endl) | writer.write(endl) | ||||
file.inputStream().run { | file.inputStream().run { | ||||
readBytes().forEach { writer.writeByte(it.toInt()) } | readBytes().forEach { writer.writeByte(it.toInt()) } | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | internal fun convertToByteArray(params: JsonValue): ByteArray { | ||||
"Because it is hard-written in the class, this error should never happen.", e) | "Because it is hard-written in the class, this error should never happen.", e) | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Reads the server's response and handles eventual exceptions. | * Reads the server's response and handles eventual exceptions. | ||||
* @return The server's response. | * @return The server's response. | ||||
* @throws IssueInTransferException If the server refuses the request, see | * @throws IssueInTransferException If the server refuses the request, see | ||||
* [getJson()][IssueInTransferException.getJson] to get the eventual error message. | * [getJson()][IssueInTransferException.json] to get the eventual error message. | ||||
*/ | */ | ||||
@Throws(IssueInTransferException::class) | @Throws(IssueInTransferException::class) | ||||
internal fun getInputStream(connection: HttpURLConnection): InputStream { | internal fun getInputStream(connection: HttpURLConnection): InputStream { | ||||
try { | try { | ||||
println("$id: Beginning reception... HTTP Status: ${connection.responseCode}") | println("$id: Beginning reception... HTTP Status: ${connection.responseCode}") | ||||
return connection.inputStream | return connection.inputStream | ||||
} catch (e: IOException) { | } catch (e: IOException) { | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |