001package Torello.Browser.BrowserAPI;
002
003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
004// Java-HTML Imports
005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
006
007import Torello.Browser.*;
008import Torello.Browser.helper.*;
009import Torello.Browser.JavaScriptAPI.*;
010import Torello.JSON.*;
011
012import Torello.Java.ReadOnly.ReadOnlyList;
013import Torello.Java.ReadOnly.ReadOnlyArrayList;
014
015import Torello.JavaDoc.Annotations.StaticFunctional;
016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg;
017
018import Torello.Browser.BrowserAPI.NestedHelpers.Commands.IO$$Commands;
019
020
021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
022// JDK Imports
023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
024
025import javax.json.JsonObject;
026import javax.json.JsonValue;
027
028/**
029 * <SPAN CLASS=COPIEDJDK><B>Input/Output operations for streams produced by DevTools.</B></SPAN>
030 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE>
031 */
032@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE")
033public class IO
034{
035    // No Pubic Constructors
036    private IO() { }
037
038
039    // ********************************************************************************************
040    // ********************************************************************************************
041    // Eliminated Types
042    // ********************************************************************************************
043    // ********************************************************************************************
044
045
046    /**
047     * This is either obtained from another method or specified as <CODE>blob:{@code <uuid>}</CODE> where
048     * <CODE>{@code <uuid>}</CODE> is an UUID of a Blob.
049
050     * <EMBED CLASS='external-html' DATA-CTAS='String' DATA-FILE-ID=CDP.EliminatedType
051     *     DATA-NAME=StreamHandle>
052     */
053    public static final String StreamHandle =
054        "StreamHandle has been eliminated.\n" +
055        "It was replaced with the standard Java-Type: String";
056
057
058
059    // ********************************************************************************************
060    // ********************************************************************************************
061    // Command-Return Types
062    // ********************************************************************************************
063    // ********************************************************************************************
064
065
066    /**
067     * Read a chunk of the stream
068     * 
069     * <EMBED CLASS=globalDefs DATA-DOMAIN=IO DATA-API=BrowserAPI DATA-CMD=read>
070     * @see IO#read
071     */
072    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_CMD_JDHBI")
073    public static class read$$RET
074        extends BaseType<read$$RET>
075        implements java.io.Serializable
076    {
077        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
078        protected static final long serialVersionUID = 1;
079
080        private static final NestedHelper<IO.read$$RET> singleton =
081            Torello.Browser.BrowserAPI.NestedHelpers.CmdReturns.
082                IO$$read$$RET.singleton;
083
084        /**
085         * Set if the data is base64-encoded
086         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
087         */
088        public final Boolean base64Encoded;
089
090        /** Data that were read. */
091        public final String data;
092
093        /** Set if the end-of-file condition occurred while reading. */
094        public final boolean eof;
095
096        /** Constructor.  Please review this class' fields for documentation. */
097        public read$$RET
098            (ReadOnlyList<Boolean> isPresent, Boolean base64Encoded, String data, boolean eof)
099        {
100            super(singleton, Domains.IO, "read", 3);
101
102            this.base64Encoded  = base64Encoded;
103            this.data           = data;
104            this.eof            = eof;
105
106            this.isPresent = (isPresent == null)
107                ? singleton.generateIsPresentList(this)
108                : THROWS.check(isPresent, 3, "IO.read$$RET");
109        }
110
111        /** Creates an instance of this class from a {@link JsonObject}.*/
112        public static read$$RET fromJSON(JsonObject jo)
113        { return singleton.fromJSON(jo); }
114
115        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
116        public static NestedDescriptor<read$$RET> descriptor()
117        { return singleton.descriptor(); }
118    }
119
120
121
122
123    // ********************************************************************************************
124    // ********************************************************************************************
125    // Commands
126    // ********************************************************************************************
127    // ********************************************************************************************
128
129
130    /**
131     * Close the stream, discard any temporary backing storage.
132     * 
133     * @param handle Handle of the stream to close.
134     * 
135     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
136     *
137     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
138     * browser receives the invocation-request.
139     *
140     * <BR /><BR /><DIV CLASS=JDHint>
141     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
142     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
143     * the Browser Function has run to completion.
144     * </DIV>
145     */
146    public static Script<Void> close(String handle)
147    {
148        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
149        final String requestJSON = WriteJSON.get
150            (CDPTypes.STRING, "handle", false, "IO.close", handle);
151
152        return Script.NO_RET(Domains.IO, "close", requestJSON);
153    }
154
155    /**
156     * Read a chunk of the stream
157     * 
158     * @param handle Handle of the stream to read.
159     * 
160     * @param offset 
161     * Seek to the specified offset before reading (if not specified, proceed with offset
162     * following the last read). Some types of streams may only support sequential reads.
163     * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
164     * 
165     * @param size Maximum number of bytes to read (left upon the agent discretion if not specified).
166     * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
167     * 
168     * @return An instance of <CODE>{@link Script}&lt;{@link read$$RET}&gt;</CODE>
169     * 
170     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
171     * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise}
172     * <CODE>&lt;{@link read$$RET}&gt;</CODE> will be returned
173     *
174     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
175     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
176     * be retrieved.</I>
177     *
178     * <BR /><BR /><DIV CLASS=JDHint>
179     * This Browser Function's {@code Promise} returns:{@link read$$RET}
180     * A dedicated return type implies that the browser may return more than 1 datum
181     * </DIV>
182     */
183    public static Script<read$$RET> read(String handle, Integer offset, Integer size)
184    {
185        // Convert all Method Parameters into a JSON Request-Object (as a String)
186        final String requestJSON = WriteJSON.get(
187            IO$$Commands.read$$, "IO.read",
188            handle, offset, size
189        );
190
191        return new Script<>(
192            Domains.IO, "read", requestJSON,
193            read$$RET::fromJSON,
194            read$$RET.class
195        );
196    }
197
198    /**
199     * Return UUID of Blob object specified by a remote object id.
200     * 
201     * @param objectId Object id of a Blob object wrapper.
202     * 
203     * @return An instance of <CODE>{@link Script}&lt;String&gt;</CODE>
204     * 
205     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
206     * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise}
207     * <CODE>&lt;String&gt;</CODE> will be returned
208     *
209     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
210     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
211     * be retrieved.</I>
212     *
213     * <BR /><BR /><DIV CLASS=JDHint>
214     * This Browser Function's {@code Promise} returns:
215     * <CODE>String (<B>uuid</B>)</CODE>
216     * <BR />
217     * UUID of the specified Blob.
218     * </DIV>
219     */
220    public static Script<String> resolveBlob(String objectId)
221    {
222        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
223        final String requestJSON = WriteJSON.get
224            (CDPTypes.STRING, "objectId", false, "IO.resolveBlob", objectId);
225
226        return new Script<>(
227            Domains.IO, "resolveBlob", requestJSON,
228            jo -> ReadJSON.getString(jo, "uuid", true, false),
229            String.class
230        );
231    }
232
233
234}