@Test public void test() throws MalformedURLException { TusURLStore store = new TusURLMemoryStore(); URL url = new URL("https://master.tus.io/files/hello"); String fingerprint = "foo"; store.set(fingerprint, url); assertEquals(store.get(fingerprint), url); store.remove(fingerprint); assertEquals(store.get(fingerprint), null); } }
urlStore.set(upload.getFingerprint(), uploadURL);
/** * Try to resume an already started upload. Before call this function, resuming must be * enabled using {@link #enableResuming(TusURLStore)}. This method will look up the URL for this * upload in the {@link TusURLStore} using the upload's fingerprint (see * {@link TusUpload#getFingerprint()}). After a successful lookup a HEAD request will be issued * to find the current offset without uploading the file, yet. * * @param upload The file for which an upload will be resumed * @return Use {@link TusUploader} to upload the remaining file's chunks. * @throws FingerprintNotFoundException Thrown if no matching fingerprint has been found in * {@link TusURLStore}. Use {@link #createUpload(TusUpload)} to create a new upload. * @throws ResumingNotEnabledException Throw if resuming has not been enabled using {@link * #enableResuming(TusURLStore)}. * @throws ProtocolException Thrown if the remote server sent an unexpected response, e.g. * wrong status codes or missing/invalid headers. * @throws IOException Thrown if an exception occurs while issuing the HTTP request. */ public TusUploader resumeUpload(@NotNull TusUpload upload) throws FingerprintNotFoundException, ResumingNotEnabledException, ProtocolException, IOException { if (!resumingEnabled) { throw new ResumingNotEnabledException(); } URL uploadURL = urlStore.get(upload.getFingerprint()); if (uploadURL == null) { throw new FingerprintNotFoundException(upload.getFingerprint()); } return beginOrResumeUploadFromURL(upload, uploadURL); }
@Test public void testResumeOrCreateUploadNotFound() throws IOException, ProtocolException { mockServer.when(new HttpRequest() .withMethod("HEAD") .withPath("/files/not_found") .withHeader("Tus-Resumable", TusClient.TUS_VERSION)) .respond(new HttpResponse() .withStatusCode(404)); mockServer.when(new HttpRequest() .withMethod("POST") .withPath("/files") .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Upload-Length", "10")) .respond(new HttpResponse() .withStatusCode(201) .withHeader("Tus-Resumable", TusClient.TUS_VERSION) .withHeader("Location", mockServerURL + "/foo")); TusClient client = new TusClient(); client.setUploadCreationURL(mockServerURL); TusURLStore store = new TusURLMemoryStore(); store.set("fingerprint", new URL(mockServerURL + "/not_found")); client.enableResuming(store); TusUpload upload = new TusUpload(); upload.setSize(10); upload.setInputStream(new ByteArrayInputStream(new byte[10])); upload.setFingerprint("fingerprint"); TusUploader uploader = client.resumeOrCreateUpload(upload); assertEquals(uploader.getUploadURL(), new URL(mockServerURL + "/foo")); }