Code Monkey home page Code Monkey logo

java7-fs-dropbox's Introduction

Read me first

This project is licensed under both LGPLv3 and ASL 2.0. See file LICENSE for more details.

What this is

This is an implementation of a Java 7 FileSystem over DropBox.

Status

There is one published version, and that is 0.0.1. You can do basic filesystem operations with it, copy, delete etc; however, it is already obsolete.

This FileSystem implementation bases itself upon java7-fs-base, which is rapidly evolving. As such, you want to have both in order to see the latest and greatest!

The above means that the codebase is changing quickly; and given the current versioning, the API is anything but stable, but progressing towards a stable state!

Usage

First of all, you MUST have a Dropbox account. Then you need to register an application. This application must have full access, and handle any types of files.

When this is done, you need to generate an OAuth 2 access token (this is also done on the apps page, however you can also generate one programmatically in theory -- if you know how, tell me!). The way you store this access token is entirely dependent upon you, but do not share it publicly!!

Then write your code! Here is a short example (imports omitted for brevity):

public final class Main
{
    private static final String ACCESS_TOKEN
        = "yourAccessTokenHere";

    private Main()
    {
        throw new Error("nice try!");
    }

    public static void main(final String... args)
        throws IOException
    {
        /*
         * Create the necessary elements to create a filesystem.
         * Note: the URI _must_ have a scheme of "dropbox", and
         * _must_ be hierarchical.
         */
        final URI uri = URI.create("dropbox://foo/");
        final Map<String, String> env = new HashMap<>();
        env.put("accessToken", ACCESS_TOKEN);

        /*
         * Create the FileSystemProvider; this will be more simple once
         * the filesystem is registered to the JRE, but right now you
         * have to do like that, sorry...
         */
        final FileSystemRepository repository
            = new DropBoxFileSystemRepository();
        final FileSystemProvider provider
            = new DropBoxFileSystemProvider(repository);

        try (
            /*
             * Create the filesystem...
             */
            final FileSystem dropboxfs = provider.newFileSystem(uri, env);
        ) {
            /*
             * And use it! You should of course adapt this code...
             */
            // Equivalent to FileSystems.getDefault().getPath(...)
            final Path src = Paths.get(System.getProperty("user.home"), "Example3.java");
            // Here we create a path for our DropBox fs...
            final Path dst = dropboxfs.getPath("/Example3.java");
            // Here we copy the file from our local fs to dropbox!
            Files.copy(src, dst);
        }
    }
}

java7-fs-dropbox's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

java7-fs-dropbox's Issues

File Attributes Bug

Hi there, thanks for your great work! I think I found a small bug in class DropBoxBasicFileAttributesProvider: It sould be

    {
        fileEntry = Objects.requireNonNull(entry).isFolder()
            ? null : entry.asFile();
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.