All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openqa.selenium.devtools.v85.io.IO Maven / Gradle / Ivy

Go to download

Selenium automates browsers. That's it! What you do with that power is entirely up to you.

There is a newer version: 4.26.0
Show newest version
package org.openqa.selenium.devtools.v85.io;

import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.ConverterFunctions;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.json.JsonInput;

/**
 * Input/Output operations for streams produced by DevTools.
 */
public class IO {

    /**
     * Close the stream, discard any temporary backing storage.
     */
    public static Command close(org.openqa.selenium.devtools.v85.io.model.StreamHandle handle) {
        java.util.Objects.requireNonNull(handle, "handle is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("handle", handle);
        return new Command<>("IO.close", params.build());
    }

    public static class ReadResponse {

        private final java.util.Optional base64Encoded;

        private final java.lang.String data;

        private final java.lang.Boolean eof;

        public ReadResponse(java.util.Optional base64Encoded, java.lang.String data, java.lang.Boolean eof) {
            this.base64Encoded = base64Encoded;
            this.data = java.util.Objects.requireNonNull(data, "data is required");
            this.eof = java.util.Objects.requireNonNull(eof, "eof is required");
        }

        /**
         * Set if the data is base64-encoded
         */
        public java.util.Optional getBase64Encoded() {
            return base64Encoded;
        }

        /**
         * Data that were read.
         */
        public java.lang.String getData() {
            return data;
        }

        /**
         * Set if the end-of-file condition occured while reading.
         */
        public java.lang.Boolean getEof() {
            return eof;
        }

        private static ReadResponse fromJson(JsonInput input) {
            java.util.Optional base64Encoded = java.util.Optional.empty();
            java.lang.String data = null;
            java.lang.Boolean eof = false;
            input.beginObject();
            while (input.hasNext()) {
                switch(input.nextName()) {
                    case "base64Encoded":
                        base64Encoded = java.util.Optional.ofNullable(input.nextBoolean());
                        break;
                    case "data":
                        data = input.nextString();
                        break;
                    case "eof":
                        eof = input.nextBoolean();
                        break;
                    default:
                        input.skipValue();
                        break;
                }
            }
            input.endObject();
            return new ReadResponse(base64Encoded, data, eof);
        }
    }

    /**
     * Read a chunk of the stream
     */
    public static Command read(org.openqa.selenium.devtools.v85.io.model.StreamHandle handle, java.util.Optional offset, java.util.Optional size) {
        java.util.Objects.requireNonNull(handle, "handle is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("handle", handle);
        offset.ifPresent(p -> params.put("offset", p));
        size.ifPresent(p -> params.put("size", p));
        return new Command<>("IO.read", params.build(), input -> input.read(org.openqa.selenium.devtools.v85.io.IO.ReadResponse.class));
    }

    /**
     * Return UUID of Blob object specified by a remote object id.
     */
    public static Command resolveBlob(org.openqa.selenium.devtools.v85.runtime.model.RemoteObjectId objectId) {
        java.util.Objects.requireNonNull(objectId, "objectId is required");
        ImmutableMap.Builder params = ImmutableMap.builder();
        params.put("objectId", objectId);
        return new Command<>("IO.resolveBlob", params.build(), ConverterFunctions.map("uuid", java.lang.String.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy