-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a88ee27
commit 0b86232
Showing
299 changed files
with
2,790 additions
and
2,307 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
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
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 +1,3 @@ | ||
rootProject.name = 'schematichq-java' | ||
|
||
include 'sample-app' |
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
package com.schematic.api.core; | ||
|
||
import java.io.InputStream; | ||
import java.util.Objects; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Represents a file stream with associated metadata for file uploads. | ||
*/ | ||
public class FileStream { | ||
private final InputStream inputStream; | ||
private final String fileName; | ||
private final MediaType contentType; | ||
|
||
/** | ||
* Constructs a FileStream with the given input stream and optional metadata. | ||
* | ||
* @param inputStream The input stream of the file content. Must not be null. | ||
* @param fileName The name of the file, or null if unknown. | ||
* @param contentType The MIME type of the file content, or null if unknown. | ||
* @throws NullPointerException if inputStream is null | ||
*/ | ||
public FileStream(InputStream inputStream, @Nullable String fileName, @Nullable MediaType contentType) { | ||
this.inputStream = Objects.requireNonNull(inputStream, "Input stream cannot be null"); | ||
this.fileName = fileName; | ||
this.contentType = contentType; | ||
} | ||
|
||
public FileStream(InputStream inputStream) { | ||
this(inputStream, null, null); | ||
} | ||
|
||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
@Nullable | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
@Nullable | ||
public MediaType getContentType() { | ||
return contentType; | ||
} | ||
|
||
/** | ||
* Creates a RequestBody suitable for use with OkHttp client. | ||
* | ||
* @return A RequestBody instance representing this file stream. | ||
*/ | ||
public RequestBody toRequestBody() { | ||
return new InputStreamRequestBody(contentType, inputStream); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/schematic/api/core/InputStreamRequestBody.java
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
package com.schematic.api.core; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Objects; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
import okhttp3.internal.Util; | ||
import okio.BufferedSink; | ||
import okio.Okio; | ||
import okio.Source; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* A custom implementation of OkHttp's RequestBody that wraps an InputStream. | ||
* This class allows streaming of data from an InputStream directly to an HTTP request body, | ||
* which is useful for file uploads or sending large amounts of data without loading it all into memory. | ||
*/ | ||
public class InputStreamRequestBody extends RequestBody { | ||
private final InputStream inputStream; | ||
private final MediaType contentType; | ||
|
||
/** | ||
* Constructs an InputStreamRequestBody with the specified content type and input stream. | ||
* | ||
* @param contentType the MediaType of the content, or null if not known | ||
* @param inputStream the InputStream containing the data to be sent | ||
* @throws NullPointerException if inputStream is null | ||
*/ | ||
public InputStreamRequestBody(@Nullable MediaType contentType, InputStream inputStream) { | ||
this.contentType = contentType; | ||
this.inputStream = Objects.requireNonNull(inputStream, "inputStream == null"); | ||
} | ||
|
||
/** | ||
* Returns the content type of this request body. | ||
* | ||
* @return the MediaType of the content, or null if not specified | ||
*/ | ||
@Nullable | ||
@Override | ||
public MediaType contentType() { | ||
return contentType; | ||
} | ||
|
||
/** | ||
* Returns the content length of this request body, if known. | ||
* This method attempts to determine the length using the InputStream's available() method, | ||
* which may not always accurately reflect the total length of the stream. | ||
* | ||
* @return the content length, or -1 if the length is unknown | ||
* @throws IOException if an I/O error occurs | ||
*/ | ||
@Override | ||
public long contentLength() throws IOException { | ||
return inputStream.available() == 0 ? -1 : inputStream.available(); | ||
} | ||
|
||
/** | ||
* Writes the content of the InputStream to the given BufferedSink. | ||
* This method is responsible for transferring the data from the InputStream to the network request. | ||
* | ||
* @param sink the BufferedSink to write the content to | ||
* @throws IOException if an I/O error occurs during writing | ||
*/ | ||
@Override | ||
public void writeTo(BufferedSink sink) throws IOException { | ||
Source source = null; | ||
try { | ||
source = Okio.source(inputStream); | ||
sink.writeAll(source); | ||
} finally { | ||
Util.closeQuietly(Objects.requireNonNull(source)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.