Sample Java snippets

This page is devoted to archiving code examples that are commonly requested -- often meaning helpful to know about. The examples are intended to be simple and intuitive for Java developers. You will notice the code examples include comments describing what is going on, and if you want to compile the code make sure you put it in the org.tranche.example package.


Downloading a project (i.e. set of files)

Tranche associates many files by using a single "project file." You can download either the project file itself or the set of files using the GetFileTool class. If you download to a file, you will get just the project file. If you download to a directory, you will get all of the files described by the project file.

This code snippet shows how to download an entire project while showing status on the command-line.

Uploading a project (i.e. set of files)

Tranche associates many files by using a single "project file." When you upload a file or set of files, a hash will be returned, which can be used to download the file or files associated with the project.

This code snippet shows how to upload an entire project while showing status on the command-line. It assumes that you already have a Tranche server on-line with a valid user file. If you don't have these, example code is included in the more verbose UploadProjectDev.java snippet.

Plain-text export a project file's contents

Tranche uses the term "project file" to describe an internal file that links together any number of individual files into a single download. Files are stored and keyed in Tranche based on their hash, meaning normally, no concept of a file name is kept. This is convenient in order to efficiently spread files across servers, and it makes it impossible to waste space in Tranche by uploading more than one copy of the same file -- only one copy is ever kept. The Tranche hash to filename mapping is preserved in a so-called project file. It is fairly straight-forward to realize how this works after visualizing one of these files.

This code snippet dumps out all of the information in a project file in plain-text.

Plain-text export a meta-data file's contents

Tranche uses the term "meta-data file" to describe an internal file that describes a single file stored on the network. This includes miscellaneous helpful information such as a default file and timestamp. The meta-data also includes other critical information such as how the data is encoded, what digital signatures are attached to the data, how the data is segmented across the network, and what annotations are linked to the data.

This code snippet dumps out all of the information in a project file in plain-text.



Home   •   FAQ   •   Contact Us   •   Join email list   •   Collaborations   •   Credits