### Get File for Input Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/tools/ForwardingJavaFileManager.html Example of getting a file for input within a package-oriented location. ```java getFileForInput(location, _packageName_, _relativeName_) ``` -------------------------------- ### Get File for Output Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/tools/ForwardingJavaFileManager.html Example of getting a file for output within a package-oriented location. ```java getFileForOutput(location, _packageName_, _relativeName_, null) ``` -------------------------------- ### Example Usage Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.jfr/jdk/jfr/Recording.html Demonstrates how to configure, start, stop, and dump recording data to disk using the Recording class. ```APIDOC ### Example ```java Configuration c = Configuration.getConfiguration("default"); Recording r = new Recording(c); r.start(); System.gc(); Thread.sleep(5000); r.stop(); r.dump(Files.createTempFile("my-recording", ".jfr")); ``` ``` -------------------------------- ### Configure, Start, Stop, and Dump Recording Data Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.jfr/jdk/jfr/Recording.html This example demonstrates how to configure, start, stop, and dump recording data to a file using the Recording class. Ensure necessary imports for Configuration, Files, and Path. ```java Configuration c = Configuration.getConfiguration("default"); Recording r = new Recording(c); r.start(); System.gc(); Thread.sleep(5000); r.stop(); r.dump(Files.createTempFile("my-recording", ".jfr")); ``` -------------------------------- ### Start a Process Pipeline with ProcessBuilder Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ProcessBuilder.html Demonstrates how to start a pipeline of processes using ProcessBuilder.startPipeline. This example counts unique import statements in Java files within a directory hierarchy on a Unix-like system. ```java String directory = "/home/duke/src"; ProcessBuilder[] builders = { new ProcessBuilder("find", directory, "-type", "f"), new ProcessBuilder("xargs", "grep", "-h", "^import "), new ProcessBuilder("awk", "{print $2;}"), new ProcessBuilder("sort", "-u")}; List processes = ProcessBuilder.startPipeline( Arrays.asList(builders)); Process last = processes.get(processes.size()-1); try (InputStream is = last.getInputStream(); Reader isr = new InputStreamReader(is); BufferedReader r = new BufferedReader(isr)) { long count = r.lines().count(); } ``` -------------------------------- ### Get File for Input Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/tools/ForwardingJavaFileManager.html Demonstrates how to get a file object for input within a package-oriented location. This is useful for accessing resources like properties files. ```java getFileForInput(SOURCE_PATH, "com.sun.tools.javac", "resources/compiler.properties"); ``` -------------------------------- ### KeyStore Instantiation and Loading Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/KeyStore.html Demonstrates how to get a KeyStore instance and load its contents, including examples for specifying an existing file, relying on the default type, and providing a specific keystore type. ```APIDOC ## KeyStore Instantiation and Loading ### Description This section provides examples of how to obtain and load a `KeyStore` object. It covers different scenarios, such as initializing a keystore from a file, using the system's default keystore type, or specifying a particular keystore type. ### Methods #### Instantiating KeyStore from a File ```java // get keystore password char[] password = getPassword(); // probe the keystore file and load the keystore entries KeyStore ks = KeyStore.getInstance(new File("keyStoreName"), password); ``` *Description*: This method probes the specified file to determine its keystore type and returns a keystore implementation with its entries already loaded. No separate `load` call is needed. #### Instantiating KeyStore with Default Type ```java KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ``` *Description*: Returns a keystore implementation for the system's default type. #### Instantiating KeyStore with Specific Type ```java KeyStore ks = KeyStore.getInstance("JKS"); ``` *Description*: Returns the most preferred implementation of the specified keystore type available in the environment. #### Loading KeyStore Entries ```java KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); // get user password and file input stream char[] password = getPassword(); try (FileInputStream fis = new FileInputStream("keyStoreName")) { ks.load(fis, password); } ``` *Description*: Loads the keystore entries from an input stream. To create an empty keystore, pass `null` as the `InputStream` argument. This method must be called unless the keystore was already loaded during instantiation. ``` -------------------------------- ### Building an HttpRequest Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.net.http/java/net/http/HttpRequest.html Demonstrates how to create an HttpRequest using its builder, set a URI, and build the request object. This example shows a basic GET request setup. ```APIDOC ## Building an HttpRequest ### Description This section illustrates the process of creating an `HttpRequest` using the `HttpRequest.Builder`. It covers obtaining a builder, setting the request's URI, and finally constructing the `HttpRequest` object. ### Method `HttpRequest.newBuilder(URI uri)` ### Endpoint N/A (This is a class method for building requests) ### Request Example (Conceptual Java Code) ```java import java.net.URI; import java.net.http.HttpRequest; // Obtain a builder with a specific URI HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create("http://example.com")); // Build the HttpRequest object HttpRequest request = builder.build(); ``` ### Response Example (Conceptual) An `HttpRequest` object configured with the specified URI. ``` -------------------------------- ### Example: Managing Full-Screen and Display Modes in Java Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/GraphicsDevice.html This example demonstrates how to enter full-screen mode using setFullScreenWindow and then attempt to change the display mode if supported. It includes fallback logic for non-full-screen operation. ```java Frame frame; DisplayMode newDisplayMode; GraphicsDevice gd; // create a Frame, select desired DisplayMode from the list of modes // returned by gd.getDisplayModes() ... if (gd.isFullScreenSupported()) { gd.setFullScreenWindow(frame); } else { // proceed in non-full-screen mode frame.setSize(...); frame.setLocation(...); frame.setVisible(true); } if (gd.isDisplayChangeSupported()) { gd.setDisplayMode(newDisplayMode); } ``` -------------------------------- ### ModelMBean Usage Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.management/javax/management/modelmbean/package-summary.html Demonstrates using a ModelMBean to expose a HashMap's 'get' method for management via an MBean server. Requires JMX setup and registration. ```java import java.lang.reflect.Method; import java.util.HashMap; import javax.management.*; import javax.management.modelmbean.*; // ... MBeanServer mbs = MBeanServerFactory.createMBeanServer(); // The MBean Server HashMap map = new HashMap(); // The resource that will be managed // Construct the management interface for the Model MBean Method getMethod = HashMap.class.getMethod("get", new Class[] {Object.class}); ModelMBeanOperationInfo getInfo = new ModelMBeanOperationInfo("Get value for key", getMethod); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(HashMap.class.getName(), "Map of keys and values", null, // no attributes null, // no constructors new ModelMBeanOperationInfo[] {getInfo}, null); // no notifications // Make the Model MBean and link it to the resource ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(map, "ObjectReference"); // Register the Model MBean in the MBean Server ObjectName mapName = new ObjectName(":type=Map,name=whatever"); mbs.registerMBean(mmb, mapName); // Resource can evolve independently of the MBean map.put("key", "value"); // Can access the "get" method through the MBean Server mbs.invoke(mapName, "get", new Object[] {"key"}, new String[] {Object.class.getName()}); // returns "value" ``` -------------------------------- ### Configure and Start a Process with Custom I/O and Environment Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ProcessBuilder.html This example demonstrates configuring a ProcessBuilder with a modified working directory, environment variables, and redirecting standard output and error to a log file. It also shows how to merge error streams. The assertions verify the redirection settings. ```java ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2"); Map env = pb.environment(); env.put("VAR1", "myValue"); env.remove("OTHERVAR"); env.put("VAR2", env.get("VAR1") + "suffix"); pb.directory(new File("myDir")); File log = new File("log"); pb.redirectErrorStream(true); pb.redirectOutput(Redirect.appendTo(log)); Process p = pb.start(); assert pb.redirectInput() == Redirect.PIPE; assert pb.redirectOutput().file() == log; ``` -------------------------------- ### Create Recording with Configuration Object Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.jfr/jdk/jfr/Recording.html Create a recording using a predefined Configuration object. The example demonstrates using the default configuration. The recording is initialized in the NEW state and needs to be started manually. ```java Recording r = new Recording(Configuration.getConfiguration("default")); ``` ```java public Recording(Configuration configuration) ``` -------------------------------- ### Start a New Process with Default Settings Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ProcessBuilder.html Use this to start a new process with the default working directory and environment. Ensure the command and its arguments are correctly specified. ```java Process p = new ProcessBuilder("myCommand", "myArg").start(); ``` -------------------------------- ### Get Start Position API Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/text/Document.html Retrieves the starting position of the document. ```APIDOC ## getStartPosition() ### Description Returns the starting position of the document. ### Method getStartPosition ### Returns - **Position** - The starting position of the document. ``` -------------------------------- ### Get Document Start Position Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/text/Document.html Retrieves the starting position of the document. ```java Position getStartPosition() ``` -------------------------------- ### init(KeyStore ks, char[] password) Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/javax/net/ssl/KeyManagerFactory.html Initializes the factory with a source of key material from a KeyStore. ```APIDOC ## POST /api/keymanagerfactory/init/keystore ### Description Initializes this factory with a source of key material. The provider typically uses a KeyStore for obtaining key material for use during secure socket negotiations. The KeyStore is generally password-protected. ### Method POST ### Endpoint /api/keymanagerfactory/init/keystore ### Parameters #### Request Body - **ks** (KeyStore) - Required - The key store or null. - **password** (char[]) - Required - The password for recovering keys in the KeyStore. ### Request Example ```json { "ks": "your_keystore_data", "password": "your_password" } ``` ### Response #### Success Response (200) - **message** (string) - Initialization successful. #### Response Example ```json { "message": "KeyManagerFactory initialized successfully." } ``` ### Throws - **KeyStoreException** - if this operation fails. - **NoSuchAlgorithmException** - if the specified algorithm is not available from the specified provider. - **UnrecoverableKeyException** - if the key cannot be recovered (e.g. the given password is wrong). ``` -------------------------------- ### Example Usage: Filtering Rows Starting with 'a' Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/RowFilter.html An example demonstrating how to implement the `include` method to filter rows where at least one column's string value starts with 'a'. ```APIDOC ```java RowFilter startsWithAFilter = new RowFilter() { public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).startsWith("a")) { // The value starts with "a", include it return true; } } // None of the columns start with "a"; return false so that this // entry is not shown return false; } }; ``` ``` -------------------------------- ### UI Installation Methods Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/plaf/basic/BasicTreeUI.html Methods related to the installation and setup of the JTree UI. ```APIDOC ## prepareForUIInstall ### Description Invoked after the `tree` instance variable has been set, but before any defaults/listeners have been installed. ### Method `prepareForUIInstall` ### Parameters None. ``` ```APIDOC ## completeUIInstall ### Description Invoked from `installUI` after all the defaults/listeners have been installed. ### Method `completeUIInstall` ### Parameters None. ``` ```APIDOC ## installDefaults ### Description Installs default properties for the UI. ### Method `installDefaults` ### Parameters None. ``` ```APIDOC ## installListeners ### Description Registers listeners for the UI. ### Method `installListeners` ### Parameters None. ``` ```APIDOC ## installKeyboardActions ### Description Registers keyboard actions for the UI. ### Method `installKeyboardActions` ### Parameters None. ``` ```APIDOC ## installComponents ### Description Installs the subcomponents of the tree, which is the renderer pane. ### Method `installComponents` ### Parameters None. ``` -------------------------------- ### KeyStore Initialization with File Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/class-use/File.html Methods for initializing KeyStore instances using File objects. ```APIDOC ## KeyStore ### Description Provides functionality for keystores (க்கப்படுகிறது). ### Methods #### `static final KeyStore` getInstance(File file, char[] password) ##### Description Returns a loaded keystore object of the appropriate keystore type. #### `static final KeyStore` getInstance(File file, KeyStore.LoadStoreParameter param) ##### Description Returns a loaded keystore object of the appropriate keystore type. ## KeyStore.Builder ### Description Provides a builder for creating KeyStore instances. ### Methods #### `static KeyStore.Builder` newInstance(File file, KeyStore.ProtectionParameter protection) ##### Description Returns a new Builder object. #### `static KeyStore.Builder` newInstance(String type, Provider provider, File file, KeyStore.ProtectionParameter protection) ##### Description Returns a new Builder object. ``` -------------------------------- ### Get Recording Start Time Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.jfr/jdk/jfr/Recording.html Returns the timestamp indicating when the recording was started. Returns null if the recording has not yet been started. ```java public Instant getStartTime() ``` -------------------------------- ### File Writing Examples - Java Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html Demonstrates various ways to open files for writing using different `OpenOption` combinations, including overwriting, appending, and creating new files. ```java Path path = ... // truncate and overwrite an existing file, or create the file if // it doesn't initially exist OutputStream out = Files.newOutputStream(path); // append to an existing file, fail if the file does not exist out = Files.newOutputStream(path, APPEND); // append to an existing file, create file if it doesn't initially exist out = Files.newOutputStream(path, CREATE, APPEND); // always create new file, failing if it already exists out = Files.newOutputStream(path, CREATE_NEW); ``` -------------------------------- ### Example Usage Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.xml/org/w3c/dom/bootstrap/DOMImplementationRegistry.html Example of how to obtain a DOMImplementationRegistry instance and get a DOM implementation for XML 3.0. ```APIDOC ## Example ```java // get an instance of the DOMImplementation registry DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); // get a DOM implementation the Level 3 XML module DOMImplementation domImpl = registry.getDOMImplementation("XML 3.0"); ``` ``` -------------------------------- ### Get Start Time Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.management/java/lang/management/RuntimeMXBean.html Returns the approximate start time of the Java Virtual Machine in milliseconds. ```APIDOC ## GET /start/time ### Description Returns the approximate start time of the Java virtual machine in milliseconds. ### Method GET ### Endpoint /start/time ### Returns - **long** - The start time of the Java virtual machine in milliseconds. ``` -------------------------------- ### Example Output 1 Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/SimpleFormatter.html Example output using the first format string. ```text WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011] ``` -------------------------------- ### atStartOfDay - Get Start of Day Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html Methods to obtain a LocalDateTime or ZonedDateTime representing the start of the day. ```APIDOC ## atStartOfDay() ### Description Combines this date with the time of midnight to create a `LocalDateTime` at the start of this date. This returns a `LocalDateTime` formed from this date at the time of midnight, 00:00, at the start of this date. ### Method `public LocalDateTime atStartOfDay()` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```json { "example": "No request body for this method" } ``` ### Response #### Success Response (200) - `LocalDateTime` - the local date-time of midnight at the start of this date, not null #### Response Example ```json { "example": "LocalDateTime object representing the start of the day" } ``` ``` ```APIDOC ## atStartOfDay(ZoneId zone) ### Description Returns a zoned date-time from this date at the earliest valid time according to the rules in the time-zone. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified zone, thus the local date-time may not be midnight. In most cases, there is only one valid offset for a local date-time. In the case of an overlap, there are two valid offsets, and the earlier one is used, corresponding to the first occurrence of midnight on the date. In the case of a gap, the zoned date-time will represent the instant just after the gap. If the zone ID is a `ZoneOffset`, then the result always has a time of midnight. ### Method `public ZonedDateTime atStartOfDay(ZoneId zone)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **zone** (ZoneId) - Required - the zone ID to use, not null ### Request Example ```json { "zone": "America/New_York" } ``` ### Response #### Success Response (200) - `ZonedDateTime` - the zoned date-time formed from this date and the earliest valid time for the zone, not null #### Response Example ```json { "example": "ZonedDateTime object representing the start of the day in the specified zone" } ``` ``` -------------------------------- ### Properties File Key-Value Examples Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Properties.html Demonstrates different ways to define key-value pairs in a properties file, including handling whitespace and multi-line values. ```properties Truth = Beauty Truth:Beauty Truth :Beauty ``` ```properties fruits apple, banana, pear, \ cantaloupe, watermelon, \ kiwi, mango ``` ```properties cheeses ``` -------------------------------- ### List Installed Attach Providers Source: https://docs.oracle.com/en/java/javase/17/docs/api/index-files/index-16.html Static method to get a list of installed attach providers. ```APIDOC ## List Installed Attach Providers ### Description Returns a list of the installed attach providers. ### Method `providers()` - Static method in class `com.sun.tools.attach.spi.AttachProvider` ### Endpoint N/A (Static Method) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **List** - A list of installed attach providers. #### Response Example None ``` -------------------------------- ### Get Location for Module Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/tools/ForwardingJavaFileManager.html Example of obtaining a package-oriented location for a specific module within a module-oriented location. ```java getLocationForModule(location, _moduleName_) ``` -------------------------------- ### Create Module Layer with Configuration Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ModuleLayer.html This example demonstrates how to create a module configuration by resolving a module named 'myapp' with the boot layer's configuration as its parent. It then defines this configuration within a new module layer, all using the system class loader. ```java ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); ModuleLayer parent = ModuleLayer.boot(); Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp")); ClassLoader scl = ClassLoader.getSystemClassLoader(); ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl); Class c = layer.findLoader("myapp").loadClass("app.Main"); ``` -------------------------------- ### Configuration.getConfiguration Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/class-use/SuppressWarnings.html Gets the installed login configuration. ```APIDOC ## Configuration.getConfiguration() ### Description Get the installed login Configuration. ### Method (Not specified, likely a static method) ### Endpoint (Not applicable) ### Parameters (None) ### Request Example (Not applicable) ### Response #### Success Response (200) - **Configuration** - The login configuration. ### Response Example (Not specified) ``` -------------------------------- ### Get Substring from Start Index Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StringBuilder.html Returns a new String containing characters from the specified start index to the end of the sequence. Throws StringIndexOutOfBoundsException if the start index is invalid. ```java public String substring(int start) ``` -------------------------------- ### Example Configuration Entry Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/javax/security/auth/login/Configuration.html Provides an example of a Configuration entry for an application named 'Login'. It demonstrates the use of 'Required' and 'Optional' flags with specific LoginModules and options, including system property expansion. ```plaintext Login { com.sun.security.auth.module.UnixLoginModule required; com.sun.security.auth.module.Krb5LoginModule optional useTicketCache="true" ticketCache="${user.home}${/}tickets"; }; ``` -------------------------------- ### Method: engineInit(KeyStore ks) Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/javax/net/ssl/TrustManagerFactorySpi.html Initializes this factory with a source of certificate authorities and related trust material. ```APIDOC ## Method: engineInit(KeyStore ks) ### Description Initializes this factory with a source of certificate authorities and related trust material. ### Signature `protected abstract void engineInit(KeyStore ks) throws KeyStoreException` ### Parameters * **ks** (`KeyStore`) - Required - The key store or null. ### Throws * `KeyStoreException` - if this operation fails. ### See Also * `TrustManagerFactory.init(KeyStore)` ``` -------------------------------- ### Get Start Position of Document Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/text/AbstractDocument.html Retrieves a position object representing the start of the document. This position will remain at the beginning of the document as it is modified. ```java public final Position getStartPosition() ``` -------------------------------- ### Example Output 2 Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/SimpleFormatter.html Example output using the second format string, demonstrating multi-line logging with exceptions. ```text Tue Mar 22 13:11:31 PDT 2011 MyClass fatal SEVERE: several message with an exception java.lang.IllegalArgumentException: invalid argument at MyClass.mash(MyClass.java:9) at MyClass.crunch(MyClass.java:6) at MyClass.main(MyClass.java:3) ``` -------------------------------- ### Internal intoByteBuffer Call Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incubator.vector/jdk/incubator/vector/LongVector.html Illustrates how intoByteArray methods internally call intoByteBuffer. This example shows the setup of a ByteBuffer and a mask for the operation. ```java var bb = ByteBuffer.wrap(a); var m = maskAll(true); intoByteBuffer(bb, offset, bo, m); ``` -------------------------------- ### ModuleFinder of System Modules Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/module/ModuleFinder.html This example demonstrates how to get a ModuleFinder for system modules. It's important to note that this requires specific security permissions. ```java static ModuleFinder ofSystem() Returns a module finder that locates the _system modules_. The system modules are the modules in the Java run-time image. The module finder will always find `java.base`. If there is a security manager set then its `checkPermission` method is invoked to check that the caller has been granted `RuntimePermission("accessSystemModules")` to access the system modules. Returns: A `ModuleFinder` that locates the system modules Throws: `SecurityException` - If denied by the security manager ``` -------------------------------- ### Example Provider Implementation Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.smartcardio/javax/smartcardio/TerminalFactorySpi.html Example Java code demonstrating how to implement a custom TerminalFactorySpi provider. ```APIDOC ## Example Provider Implementation ### MyProvider.java ```java package com.somedomain.card; import java.security.Provider; public class MyProvider extends Provider { public MyProvider() { super("MyProvider", 1.0d, "Smart Card Example"); put("TerminalFactory.MyType", "com.somedomain.card.MySpi"); } } ``` ### MySpi.java ```java package com.somedomain.card; import javax.smartcardio.*; public class MySpi extends TerminalFactorySpi { public MySpi(Object parameter) { // initialize as appropriate } protected CardTerminals engineTerminals() { // add implementation code here } } ``` ``` -------------------------------- ### Example Service Provider Configuration File Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/spi/LocaleServiceProvider.html This example shows the structure of a service provider configuration file for a DateFormatProvider implementation. The file name is the fully qualified provider interface class name, and it lists the fully qualified concrete provider class names, one per line. ```text META-INF/services/java.text.spi.DateFormatProvider ``` -------------------------------- ### Look and Feel Management Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/UIManager.html Methods for getting, installing, and setting the current LookAndFeel. ```APIDOC ## Look and Feel Management ### Description Provides functionality to manage the current and available LookAndFeel implementations. ### Methods #### `getLookAndFeel()` - **Method**: GET - **Endpoint**: `/UIManager/lookAndFeel` - **Description**: Returns the current look and feel or `null`. - **Response**: `LookAndFeel` (or null) #### `getInstalledLookAndFeels()` - **Method**: GET - **Endpoint**: `/UIManager/installedLookAndFeels` - **Description**: Returns an array of `LookAndFeelInfo`s representing the `LookAndFeel` implementations currently available. - **Response**: `UIManager.LookAndFeelInfo[]` #### `installLookAndFeel(String name, String className)` - **Method**: POST - **Endpoint**: `/UIManager/installLookAndFeel` - **Description**: Adds the specified look and feel to the set of available look and feels. - **Request Body**: - **name** (String) - Required - The name of the look and feel. - **className** (String) - Required - The class name of the look and feel. #### `installLookAndFeel(UIManager.LookAndFeelInfo info)` - **Method**: POST - **Endpoint**: `/UIManager/installLookAndFeel` - **Description**: Adds the specified look and feel to the set of available look and feels. - **Request Body**: - **info** (UIManager.LookAndFeelInfo) - Required - The LookAndFeel info object. #### `setLookAndFeel(String className)` - **Method**: PUT - **Endpoint**: `/UIManager/lookAndFeel` - **Description**: Loads and sets the `LookAndFeel` specified by the given class name. - **Request Body**: - **className** (String) - Required - The class name of the look and feel to set. #### `setLookAndFeel(LookAndFeel newLookAndFeel)` - **Method**: PUT - **Endpoint**: `/UIManager/lookAndFeel` - **Description**: Sets the current look and feel to the provided `LookAndFeel` object. - **Request Body**: - **newLookAndFeel** (LookAndFeel) - Required - The new LookAndFeel object. #### `setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)` - **Method**: PUT - **Endpoint**: `/UIManager/installedLookAndFeels` - **Description**: Sets the entire set of available look and feels. - **Request Body**: - **infos** (UIManager.LookAndFeelInfo[]) - Required - An array of LookAndFeelInfo objects. #### `removeAuxiliaryLookAndFeel(LookAndFeel laf)` - **Method**: DELETE - **Endpoint**: `/UIManager/auxiliaryLookAndFeel` - **Description**: Removes a `LookAndFeel` from the list of auxiliary look and feels. - **Request Body**: - **laf** (LookAndFeel) - Required - The LookAndFeel to remove. ``` -------------------------------- ### Creating and Using a Buffer Strategy Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/image/BufferStrategy.html Example demonstrating how to create and use a general double-buffering strategy for a Window. Ensure to check GraphicsConfiguration capabilities and handle buffer restoration and loss within the rendering loop. ```java // Check the capabilities of the GraphicsConfiguration ... // Create our component Window w = new Window(gc); // Show our window w.setVisible(true); // Create a general double-buffering strategy w.createBufferStrategy(2); BufferStrategy strategy = w.getBufferStrategy(); // Main loop while (!done) { // Prepare for rendering the next frame // ... // Render single frame do { // The following loop ensures that the contents of the drawing buffer // are consistent in case the underlying surface was recreated do { // Get a new graphics context every time through the loop // to make sure the strategy is validated Graphics graphics = strategy.getDrawGraphics(); // Render to graphics // ... // Dispose the graphics graphics.dispose(); // Repeat the rendering if the drawing buffer contents // were restored } while (strategy.contentsRestored()); // Display the buffer strategy.show(); // Repeat the rendering if the drawing buffer was lost } while (strategy.contentsLost()); } // Dispose the window w.setVisible(false); w.dispose(); ``` -------------------------------- ### Get All Providers Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/Security.html Retrieves an array of all installed security providers in their preference order. ```APIDOC ## GET /api/security/providers ### Description Returns an array containing all the installed providers. The order of the providers in the array is their preference order. ### Method GET ### Endpoint /api/security/providers ### Response #### Success Response (200) - **providers** (Provider[]) - An array of all installed security providers. #### Response Example ```json { "providers": [ { "name": "SUN", "version": "1.8", "className": "sun.security.provider.Sun" }, { "name": "SunRsaSign", "version": "1.8", "className": "sun.security.rsa.SunRsaSign" } ] } ``` ``` -------------------------------- ### Example Usage of resolve() Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/module/Configuration.html An example demonstrating how to use the `resolve` method to find modules and their dependencies, using the boot layer configuration as a parent. ```APIDOC ## Example The following example uses the `resolve` method to resolve a module named _myapp_ with the configuration for the boot layer as the parent configuration. It prints the name of each resolved module and the names of the modules that each module reads. ```java ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp")); cf.modules().forEach(m -> { System.out.format("%s -> %s%n", m.name(), m.reads().stream() .map(ResolvedModule::name) .collect(Collectors.joining(", ")) ); }); ``` ``` -------------------------------- ### JAR URL Syntax Examples Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/JarURLConnection.html Illustrates the syntax for JAR URLs, including references to specific entries, entire JAR files, and directories within a JAR. ```plaintext jar:!/{entry} ``` ```plaintext jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class ``` ```plaintext jar:http://www.foo.com/bar/baz.jar!/ ``` ```plaintext jar:http://www.foo.com/bar/baz.jar!/COM/foo/ ``` -------------------------------- ### Get DecimalFormatSymbols Instance for Default Locale Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/text/DecimalFormatSymbols.html Gets the DecimalFormatSymbols instance for the default locale. This method provides access to instances supported by the Java runtime and installed providers. ```java public static final DecimalFormatSymbols getInstance() Gets the DecimalFormatSymbols instance for the default locale. This method provides access to DecimalFormatSymbols instances for locales supported by the Java runtime itself as well as for those supported by installed DecimalFormatSymbolsProvider implementations. This is equivalent to calling getInstance(Locale.getDefault(Locale.Category.FORMAT)). Returns: a DecimalFormatSymbols instance. Since: 1.6 ``` -------------------------------- ### get Method Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ClassValue.html The public T get(Class type) method returns the value for the given class. If no value has been computed, it is obtained by invoking computeValue. The value is installed atomically. ```APIDOC ### get public T get(Class type) Returns the value for the given class. If no value has yet been computed, it is obtained by an invocation of the `computeValue` method. The actual installation of the value on the class is performed atomically. At that point, if several racing threads have computed values, one is chosen, and returned to all the racing threads. The `type` parameter is typically a class, but it may be any type, such as an interface, a primitive type (like `int.class`), or `void.class`. In the absence of `remove` calls, a class value has a simple state diagram: uninitialized and initialized. When `remove` calls are made, the rules for value observation are more complex. See the documentation for `remove` for more information. Parameters: `type` - the type whose class value must be computed or retrieved Returns: the current value associated with this `ClassValue`, for the given class or interface Throws: `NullPointerException` - if the argument is null See Also: * `remove(java.lang.Class)` * `computeValue(java.lang.Class)` ``` -------------------------------- ### Default Configuration Syntax Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/javax/security/auth/login/Configuration.html Illustrates the default syntax for a Configuration object, showing application-specific entries with LoginModules, flags, and options. Subclass implementations may use alternative syntaxes. ```plaintext Name { ModuleClass Flag ModuleOptions; ModuleClass Flag ModuleOptions; ModuleClass Flag ModuleOptions; }; Name { ModuleClass Flag ModuleOptions; ModuleClass Flag ModuleOptions; }; other { ModuleClass Flag ModuleOptions; ModuleClass Flag ModuleOptions; }; ``` -------------------------------- ### Get Matcher Region Start Index Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Matcher.html Returns the starting index (inclusive) of the region within the input sequence that the matcher searches. Searches are limited to the defined region. ```java public int regionStart() ``` -------------------------------- ### Example Usage: Module Configuration and Layer Creation Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ModuleLayer.html This example demonstrates how to create a module configuration by resolving a specific module and then defining new module layers based on that configuration. ```APIDOC ## Example Usage: Module Configuration and Layer Creation ### Description This example creates a configuration by resolving a module named "`myapp`" with the configuration for the boot layer as the parent. It then creates a new layer with the modules in this configuration. All modules are defined to the same class loader. ### Code Example ```java ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3); ModuleLayer parent = ModuleLayer.boot(); Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp")); ClassLoader scl = ClassLoader.getSystemClassLoader(); ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl); Class c = layer.findLoader("myapp").loadClass("app.Main"); ``` ### Since 9 ### See Also - `Module.getLayer()` ``` -------------------------------- ### Custom Date Comparison Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/SpinnerDateModel.html An example of a custom class implementing Comparable to define a specific start date for a SpinnerDateModel. Note the potential for ClassCastException if non-Date objects are compared. ```java MyStartDate implements Comparable { long t = 12345; public int compareTo(Date d) { return (t < d.getTime() ? -1 : (t == d.getTime() ? 0 : 1)); } public int compareTo(Object o) { return compareTo((Date)o); } } ``` -------------------------------- ### Example Usage Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.httpserver/com/sun/net/httpserver/HttpsConfigurator.html An example demonstrating how to configure HTTPS parameters using HttpsConfigurator. ```APIDOC ## Example Usage ```java SSLContext sslContext = SSLContext.getInstance (....); HttpsServer server = HttpsServer.create(); server.setHttpsConfigurator (new HttpsConfigurator(sslContext) { public void configure (HttpsParameters params) { // get the remote address if needed InetSocketAddress remote = params.getClientAddress(); SSLContext c = getSSLContext(); // get the default parameters SSLParameters sslparams = c.getDefaultSSLParameters(); if (remote.equals (...) ) { // modify the default set for client x } params.setSSLParameters(sslparams); } }); ``` ``` -------------------------------- ### Static Method: newInstance(File file, KeyStore.ProtectionParameter protection) Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/KeyStore.Builder.html Creates a new KeyStore.Builder instance that will load a KeyStore from the specified file. ```APIDOC ## Method: newInstance(File file, KeyStore.ProtectionParameter protection) ### Description Returns a new Builder object that will load a KeyStore from the specified file. ### Parameters * **file** (File) - The file from which to load the KeyStore. * **protection** (KeyStore.ProtectionParameter) - The protection parameter to use for loading the KeyStore. ### Return Type `static KeyStore.Builder` ``` -------------------------------- ### Get Substring with Start and End Indices Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StringBuilder.html Returns a new String containing characters from the specified start index up to (but not including) the end index. Throws StringIndexOutOfBoundsException for invalid indices. ```java public String substring(int start, int end) ``` -------------------------------- ### Accessing Field Value Example Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.jdi/com/sun/jdi/Value.html Illustrates how to get the value of a field using ObjectReference.getValue(Field). ```java ObjectReference.getValue(Field) ``` -------------------------------- ### FileSystem newFileSystem(Path path, Map env) Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/FileSystems.html This method makes use of specialized providers that create pseudo file systems where the contents of one or more files is treated as a file system. This method first attempts to locate an installed provider in exactly the same manner as the `newFileSystem(Path, Map, ClassLoader)` method. If found, the provider's `newFileSystem(Path, Map)` method is invoked with an empty map to construct the new file system. ```APIDOC ## POST /newFileSystem ### Description Creates a pseudo file system from the contents of a file. This method attempts to locate an installed provider and invokes its `newFileSystem(Path, Map)` method. ### Method POST ### Endpoint /newFileSystem ### Parameters #### Path Parameters - **path** (Path) - Required - the path to the file - **env** (Map) - Required - a map of provider specific properties to configure the file system; may be empty ### Request Body ```json { "path": "/path/to/file", "env": {} } ``` ### Response #### Success Response (200) - **FileSystem** (FileSystem) - a new file system #### Response Example ```json { "fileSystem": "newFileSystemObject" } ``` ### Throws - **ProviderNotFoundException** - if a provider supporting this file type cannot be located - **ServiceConfigurationError** - when an error occurs while loading a service provider - **IOException** - if an I/O error occurs - **SecurityException** - if a security manager is installed and it denies an unspecified permission ``` -------------------------------- ### Example Keystore Domain Configuration Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/DomainLoadStoreParameter.html This example demonstrates the configuration for a keystore domain named 'app1', comprising three distinct keystores with specified URIs and types. ```plaintext domain app1 { keystore app1-truststore keystoreURI="file:///app1/etc/truststore.jks"; keystore system-truststore keystoreURI="${java.home}/lib/security/cacerts"; keystore app1-keystore keystoreType="PKCS12" keystoreURI="file:///app1/etc/keystore.p12"; }; ``` -------------------------------- ### Get SpinnerDateModel Start Limit Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/SpinnerDateModel.html Returns the first Date in the sequence, which represents the lower bound. ```java public Comparable getStart() ``` -------------------------------- ### KeyAgreementSpi engineInit methods with SecureRandom Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/class-use/SecureRandom.html Demonstrates the initialization of KeyAgreementSpi with a SecureRandom source. ```APIDOC ## KeyAgreementSpi.engineInit(Key key, SecureRandom random) ### Description Initializes this key agreement with the given key and source of randomness. ### Method `protected abstract void` ### Endpoint N/A (Method Signature) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## KeyAgreementSpi.engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) ### Description Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness. ### Method `protected abstract void` ### Endpoint N/A (Method Signature) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Text Selection Management Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/TextComponent.html Methods for getting and setting the start and end positions of selected text. ```APIDOC ## GET /api/text/selection/start ### Description Gets the start position of the selected text in this text component. ### Method GET ### Endpoint /api/text/selection/start ### Response #### Success Response (200) - **selectionStart** (int) - The start position of the selected text. #### Response Example { "selectionStart": 0 } ``` ```APIDOC ## POST /api/text/selection/end ### Description Gets the end position of the selected text in this text component. ### Method POST ### Endpoint /api/text/selection/end ### Response #### Success Response (200) - **selectionEnd** (int) - The end position of the selected text. #### Response Example { "selectionEnd": 10 } ``` ```APIDOC ## PUT /api/text/selection/end ### Description Sets the selection end for this text component to the specified position. The new end point is constrained to be at or after the current selection start and cannot be set beyond the end of the component's text. ### Method PUT ### Endpoint /api/text/selection/end ### Parameters #### Request Body - **selectionEnd** (int) - Required - The end position of the selected text. ### Request Example { "selectionEnd": 15 } ### Response #### Success Response (200) - **message** (string) - Indicates successful update. #### Response Example { "message": "Selection end updated successfully." } ``` ```APIDOC ## PUT /api/text/select ### Description Selects the text between the specified start and end positions. Enforces constraints on start and end positions. ### Method PUT ### Endpoint /api/text/select ### Parameters #### Request Body - **selectionStart** (int) - Required - The zero-based index of the first character to be selected. - **selectionEnd** (int) - Required - The zero-based end position of the text to be selected (the character at this position is not selected). ### Request Example { "selectionStart": 5, "selectionEnd": 20 } ### Response #### Success Response (200) - **message** (string) - Indicates successful selection. #### Response Example { "message": "Text selected successfully." } ``` ```APIDOC ## POST /api/text/select/all ### Description Selects all the text in this text component. ### Method POST ### Endpoint /api/text/select/all ### Response #### Success Response (200) - **message** (string) - Indicates successful selection of all text. #### Response Example { "message": "All text selected successfully." } ``` -------------------------------- ### Example: Setting Properties with States Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/plaf/synth/doc-files/synthFileFormat.html Demonstrates how to set default properties and state-specific properties, such as icons for different component states like mouse-over. ```xml ``` -------------------------------- ### Example: Creating an Animated Image Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/image/MemoryImageSource.html This example shows how to set up an animation source using MemoryImageSource and signal changes in the pixel data for animation. ```APIDOC ```java int pixels[]; MemoryImageSource source; public void init() { int width = 50; int height = 50; int size = width * height; pixels = new int[size]; int value = getBackground().getRGB(); for (int i = 0; i < size; i++) { pixels[i] = value; } source = new MemoryImageSource(width, height, pixels, 0, width); source.setAnimated(true); image = createImage(source); } public void run() { Thread me = Thread.currentThread(); me.setPriority(Thread.MIN_PRIORITY); while (true) { try { Thread.sleep(10); } catch( InterruptedException e ) { return; } // Modify the values in the pixels array at (x, y, w, h) // Send the new data to the interested ImageConsumers source.newPixels(x, y, w, h); } } ``` ``` -------------------------------- ### Get Handshake Application Protocol Source: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/javax/net/ssl/SSLSocket.html Retrieves the application protocol string from an SSLSocket's handshake. This example shows how to get the string and convert it to bytes for comparison, using both ISO-8859-1 and UTF-8 character sets. ```java String networkString = sslSocket.getHandshakeApplicationProtocol(); byte[] bytes = networkString.getBytes(StandardCharsets.ISO_8859_1); // // Match using bytes: // // "http/1.1" (7-bit ASCII values same in UTF-8) // MEETEI MAYEK LETTERS "HUK UN I" (Unicode 0xabcd->0xabcf) // String HTTP1_1 = "http/1.1"; byte[] HTTP1_1_BYTES = HTTP1_1.getBytes(StandardCharsets.UTF_8); byte[] HUK_UN_I_BYTES = new byte[] { (byte) 0xab, (byte) 0xcd, ``` -------------------------------- ### SourcePositions Methods Source: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.compiler/com/sun/source/tree/class-use/Tree.html Provides methods to get the start and end positions of a tree within a compilation unit. ```APIDOC ## GET SourcePositions.getEndPosition ### Description Returns the ending position of tree within file. ### Method GET ### Endpoint /SourcePositions/getEndPosition ### Parameters #### Path Parameters - **file** (CompilationUnitTree) - Required - The compilation unit file. - **tree** (Tree) - Required - The tree node. ### Response #### Success Response (200) - **long** - The ending position of the tree. ``` ```APIDOC ## GET SourcePositions.getStartPosition ### Description Returns the starting position of tree within file. ### Method GET ### Endpoint /SourcePositions/getStartPosition ### Parameters #### Path Parameters - **file** (CompilationUnitTree) - Required - The compilation unit file. - **tree** (Tree) - Required - The tree node. ### Response #### Success Response (200) - **long** - The starting position of the tree. ```