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

reference.language.resources.html Maven / Gradle / Ivy




    
    Resources
    
    

    
    

    
    

    
    
    
    

    


Resources

Some system resources require careful handling. For example, when you open a file for writing, the file is locked and becomes unavailable for reading by other programs, or other parts of your application. Similar constraints apply to other objects: network objects such as Urls, database connections, and so on.

A Prompto resource is a specialized native category designed to take care of these precious resources, and free them automatically as soon as possible. To achieve this, Prompto requires resources to be either inlined or managed. An inlined resource is one that is not assigned to a variable, but rather used as an expression, and cannot therefore be accessed more than once. A managed resource is one that is protected using a with block.

It is illegal to read or write a resource which is neither managed nor inlined.

Prompto resources are used to read and write text. There is no support for binary data. If required, binary data should be handled and converted to or from Prompto objects using the host language.

Reading text from a resource

In the below examples, we use a Url resource. File resources are not accessible from a browser.

Prompto resources can be used to read text, either line per line, or all lines at once.

Read all the text from an inlined resource

When reading all the lines at once, you can simply specify the resource as a parameter to the read all statement.

Read the text line by line from a managed resource

To read the text line by line, you must manage the resource using a with block:

Writing text to a resource

In the below examples, we use a Buffer resource. File resources are not accessible from a browser.

Prompto can write text to resources, either line per line, or all lines at once.

Writing all the text to an inlined resource

When writing all the text at once, you can simply specify the resource as a parameter to the write statement.

Writing the text line by line to a managed resource

To write the text line by line, you must manage the resource using a with block:

Prompto native resource specification

A Prompto native resource must implement:

  • a close method, which is called automatically by Prompto when appropriate. This method cannot be called directly by Prompto code.
  • a isReadable method, which is called to check whether a resource supports read methods
  • a isWritable method, which is called to check whether a resource supports write methods
  • a readLine method, which must return the next line of text from the resource, or null if no more data is available
  • a readFully method, which must return the entire text from the resource, or null if no data is available
  • a writeLine method, which must append a line of text to the resource
  • a writeFully method, which must overwrite the entire content of the resource with the incoming text
see an example in Prompto
see an example in Java
see an example in C#
see an example in Python
see an example in JavaScript





© 2015 - 2025 Weber Informatics LLC | Privacy Policy