LabPal User Manual
  • Easily run experiments on a computer
  • A quick tutorial
    • Creating an experiment
    • Creating a lab
    • Creating a lab
    • Adding a table
    • Adding a plot
    • Wrapping up
    • Advanced functionalities
  • Using the web console
    • Typical usage of the web console
    • The elements of the web console
    • Running a lab on a remote machine
    • Changing the server port
    • Changing the color scheme
  • Using the text console
  • Experiments: advanced features
    • Use multiple types of experiments in the same lab
    • Use table transformations
    • Make experiments that depend on external resources
    • Dealing with errors
    • Update a progress indicator for long experiments
    • Guess the execution time of an experiment
    • Generate multiple data points in a single experiment
    • Group experiments
  • Creating and transforming tables
  • Creating plots
    • Plot libraries
    • Two-dimensional plots
    • Customizing GRAL plots
    • Palettes
  • Managing files
    • Using the FileHelper
    • Bundling external resources
  • Saving, loading, merging labs
    • Save a lab
    • Load a lab
    • Merge labs
    • Preload a lab with results stored internally
    • Export a lab notebook
    • Be careful with serialization
  • Adding metadata
    • To the lab
    • To each experiment group
    • To each experiment
    • To each parameter
  • Creating regions
    • Iterating over regions
    • Irregular regions
    • Regions are objects
    • Filtering experiments
    • Counting points
  • Calling external commands
  • Including external results
    • By hand
    • Automatically from a file
  • Running LabPal on multiple machines
    • Auto-reporting
    • Filtering
    • Auto-start
  • Data Provenance and Traceability
  • Verifying claims on experiments
    • The Claim object
    • Viewing claims
    • Explaining violations
    • Claims as integrity checks
  • Playing with the lab's parameters
    • Change the code
    • Edit experiments in the web console
  • Other features
    • Passing command-line parameters
    • Customizing the web console
    • Checking the environment
    • Creating a lab in Python
Powered by GitBook
On this page
  • Using the FileHelper
  • Bundling internal resources

Managing files

PreviousPalettesNextUsing the FileHelper

Last updated 6 years ago

So far, our running examples did not need any external file to be run; if they did, they were generated dynamically as . However, a laboratory can also be bundled with additional files that can be read by your Java code.

If you are using the (which we recommend), the lab's source files are organized like this:

/labpal-project
  Readme.md
  /Source
    /src
      MyLaboratory.java
      MyExperiment.java
      ...
    /bin

If you with to include data files or other resources in your lab, simply put them somewhere under the src folder where your source files are located. We call these files internal resources; the way to access these files is slightly different from normal files somewhere else in your computer.

Using the FileHelper

LabPal contains a class called , which provides a number of methods for manipulating files. To access internal resources, you must use either of these methods:

  • internalFileToBytes

  • internalFileToString

  • internalFileToStream

Suppose for example that your lab contains an image file, bird.jpg, located directly in the "src" folder. To read that file as an array of bytes, you would do the following:

byte[] contents = FileHelper.internalFileToBytes(MyLaboratory.class, "bird.jpg");

The first argument passed to the method is a class; FileHelper uses this class to fetch the desired file relative to some location in the project. Since MyLaboratory is located in the "src" folder, the file path given as an argument will be relative to this folder.

You can obviously create folders in your project; for example, put the image files into a subfolder called "images":

/labpal-project
  Readme.md
  /Source
    /src
      MyLaboratory.java
      MyExperiment.java
      /images
        bird.jpg
    /bin

Simply mention the full path to the resource when reading it:

byte[] contents = FileHelper.internalFileToBytes(MyLaboratory.class, "images/bird.jpg");

Bundling internal resources

The template project comes with an Ant build script that compiles the lab. At the command line, simply type:

$ ant

This will create a JAR file called my-lab.jar (or something else if you changed the settings in config.xml).

A nice feature of internal resources is that they are bundled inside the JAR. As a matter of fact, if you open the file in an archive manager, you will see that all the internal files you put in your src folder are there, organized in exactly the same way. Therefore, the JAR file is not just an executable program: it also acts as the archive for your data files.

This greatly simplifies the execution of your lab by somebody else. There is no need for a user to copy files in specific locations before running the experiments: the lab comes with its own internal, mini-filesystem.

prerequisites
template project
FileHelper