DropboxAPI { public List<Entry> search(String path, String query, int fileLimit, boolean includeDeleted) throws DropboxException { assertAuthenticated(); if (fileLimit <= 0) { fileLimit = SEARCH_DEFAULT_LIMIT; } String target = "/search/" + session.getAccessType() + path; String[] params = { "query", query, "file_limit", String.valueOf(fileLimit), "include_deleted", String.valueOf(includeDeleted), "locale", session.getLocale().toString() }; Object response = RESTUtility.request(RequestMethod.GET, session.getAPIServer(), target, VERSION, params, session); ArrayList<Entry> ret = new ArrayList<Entry>(); if (response instanceof JSONArray) { JSONArray jresp = (JSONArray)response; for (Object next: jresp) { if (next instanceof Map) { @SuppressWarnings("unchecked") Entry ent = new Entry((Map<String, Object>)next); ret.add(ent); } } } return ret; } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
                                                     ProgressListener listener,
                                                     long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
            ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
            String parentRev, ProgressListener listener); Entry putFile(String path, InputStream is, long length,
            String parentRev, boolean autoRename, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
            long length, String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
            long length, String parentRev, boolean autoRename, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
            ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
            long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
            ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
            ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
            boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
            boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; }
@Test public void search() throws Exception { try { api.search("/", "", 1000, false); assert false: "Short (empty) search string did not throw an error."; } catch (DropboxServerException e) { if (e.error != DropboxServerException._400_BAD_REQUEST) { assert false: "Unexpected Dropbox Error: " + e.toString(); } } String searchDir = TESTS_DIR + "/searchDir/"; uploadFile(foo, searchDir + "text.txt"); uploadFile(foo, searchDir + "subFolder/text.txt"); uploadFile(foo, searchDir + "subFolder/cow.txt"); uploadFile(frog, searchDir + "frog.jpg"); uploadFile(frog, searchDir + "frog2.jpg"); uploadFile(frog, searchDir + "subFolder/frog2.jpg"); List<Entry> results = api.search(searchDir, "sadfasdf", 1000, false); assertEquals(results.size(), 0); results = api.search(searchDir, "jpg", 1000, false); assertEquals(results.size(), 3); HashSet<String> resultPaths = new HashSet<String>(); for (DropboxAPI.Entry e : results) { assertEquals(e.bytes, frog.length()); assertEquals(e.isDir, false); resultPaths.add(e.path); } resultPaths.equals(new HashSet<String>(Arrays.asList( searchDir + "frog.jpg", searchDir + "frog2.jpg", searchDir + "subFolder/frog2.jpg"))); results = api.search(searchDir + "subFolder", "jpg", 1000, false); assertEquals(results.size(), 1); assertFile(results.get(0), frog, searchDir + "subFolder/frog2.jpg"); }