List of usage examples for java.lang InterruptedException InterruptedException
public InterruptedException(String s)
InterruptedException
with the specified detail message. From source file:io.pyd.synchro.SyncJob.java
protected boolean synchronousUP(Node folderNode, final File sourceFile, Node remoteNode) throws Exception { if (getCoreManager().getRdiffProc() != null && getCoreManager().getRdiffProc().rdiffEnabled()) { // RDIFF ! File signatureFile = tmpFileName(sourceFile, "sig"); boolean remoteHasSignature = false; try {/*from w ww . ja va 2s .c o m*/ this.uriContentToFile(AjxpAPI.getInstance().getFilehashSignatureUri(remoteNode), signatureFile, null); remoteHasSignature = true; } catch (IllegalStateException e) { } if (remoteHasSignature && signatureFile.exists() && signatureFile.length() > 0) { // Compute delta File deltaFile = tmpFileName(sourceFile, "delta"); RdiffProcessor proc = getCoreManager().getRdiffProc(); proc.delta(signatureFile, sourceFile, deltaFile); signatureFile.delete(); if (deltaFile.exists()) { // Send back to server RestRequest rest = this.getRequest(); logChange(getMessage("job_log_updelta"), sourceFile.getName()); String patchedFileMd5 = rest.getStringContent( AjxpAPI.getInstance().getFilehashPatchUri(remoteNode), null, deltaFile, null); rest.release(); deltaFile.delete(); // String localMD5 = (folderNode) if (patchedFileMd5.trim().equals(SyncJob.computeMD5(sourceFile))) { // OK ! return true; } } } } final long totalSize = sourceFile.length(); if (!sourceFile.exists() || totalSize == 0) { throw new FileNotFoundException("Cannot find file :" + sourceFile.getAbsolutePath()); } Logger.getRootLogger().info("Uploading " + totalSize + " bytes"); RestRequest rest = this.getRequest(); // Ping to make sure the user is logged rest.getStatusCodeForRequest(AjxpAPI.getInstance().getAPIUri()); // final long filesize = totalSize; rest.setUploadProgressListener(new CountingMultipartRequestEntity.ProgressListener() { private int previousPercent = 0; private int currentPart = 0; private int currentTotal = 1; @Override public void transferred(long num) throws IOException { if (SyncJob.this.interruptRequired) { throw new IOException("Upload interrupted on demand"); } int currentPercent = (int) (num * 100 / totalSize); if (this.currentTotal > 1) { long partsSize = totalSize / this.currentTotal; currentPercent = (int) (((partsSize * this.currentPart) + num) * 100 / totalSize); } currentPercent = Math.min(Math.max(currentPercent, 0), 100); if (currentPercent > previousPercent) { logChange(getMessage("job_log_uploading"), currentPercent + "%" + " - " + sourceFile.getName()); } previousPercent = currentPercent; } @Override public void partTransferred(int part, int total) throws IOException { this.currentPart = part; this.currentTotal = total; if (SyncJob.this.interruptRequired) { throw new IOException("Upload interrupted on demand"); } logChange(getMessage("job_log_uploading"), "[" + (part + 1) + "/" + total + "] " + sourceFile.getName()); } }); String targetName = sourceFile.getName(); try { rest.getStringContent(AjxpAPI.getInstance().getUploadUri(folderNode.getPath(true)), null, sourceFile, targetName, 200); } catch (IOException ex) { if (this.interruptRequired) { rest.release(); throw new InterruptedException("Interrupt required"); } } rest.release(); return false; }
From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.TestConsoleLicenseGenerator.java
@Test public void testRun06() throws Exception { this.console = EasyMock.createMockBuilder(ConsoleLicenseGenerator.class) .withConstructor(TextInterfaceDevice.class, CommandLineParser.class) .withArgs(this.device, new GnuParser()).addMockedMethod("processCommandLineOptions") .addMockedMethod("initializeLicenseCreator").addMockedMethod("generateLicense").createStrictMock(); String[] arguments = new String[] { "help" }; this.console.processCommandLineOptions(arguments); EasyMock.expectLastCall();//from w w w .j a va 2 s. c o m this.console.initializeLicenseCreator(); EasyMock.expectLastCall(); this.console.generateLicense(); EasyMock.expectLastCall().andThrow(new InterruptedException("message06.")); this.device.printErrLn("The system was interrupted while waiting for events to complete."); EasyMock.expectLastCall(); this.device.exit(44); EasyMock.expectLastCall(); EasyMock.replay(this.device, this.console); try { this.console.run(arguments); } finally { EasyMock.verify(this.console); } }
From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.TestConsoleRSAKeyPairGenerator.java
@Test public void testRun07() throws Exception { this.console = EasyMock.createMockBuilder(ConsoleRSAKeyPairGenerator.class) .withConstructor(RSAKeyPairGeneratorInterface.class, TextInterfaceDevice.class, CommandLineParser.class) .withArgs(this.generator, this.device, new GnuParser()) .addMockedMethod("processCommandLineOptions", String[].class).addMockedMethod("doInteractive") .addMockedMethod("doCommandLine").createStrictMock(); String[] arguments = new String[] { "-private" }; this.console.processCommandLineOptions(arguments); EasyMock.expectLastCall();/*w w w . j a v a2s . co m*/ this.console.doCommandLine(); EasyMock.expectLastCall().andThrow(new InterruptedException("Message 07.")); this.device.printErrLn("The system was interrupted while waiting for events to complete."); EasyMock.expectLastCall(); this.device.exit(44); EasyMock.expectLastCall(); EasyMock.replay(this.console, this.generator, this.device); try { this.console.run(arguments); } finally { EasyMock.verify(this.console); } }
From source file:org.apache.manifoldcf.crawler.connectors.wiki.WikiConnector.java
protected static void handleException(Throwable thr) throws InterruptedException, ManifoldCFException, ServiceInterruption, IOException, HttpException { if (thr != null) { if (thr instanceof ManifoldCFException) { if (((ManifoldCFException) thr).getErrorCode() == ManifoldCFException.INTERRUPTED) { throw new InterruptedException(thr.getMessage()); }/* w w w . j a v a2 s . c o m*/ throw (ManifoldCFException) thr; } else if (thr instanceof ServiceInterruption) { throw (ServiceInterruption) thr; } else if (thr instanceof IOException) { throw (IOException) thr; } else if (thr instanceof HttpException) { throw (HttpException) thr; } else if (thr instanceof RuntimeException) { throw (RuntimeException) thr; } else if (thr instanceof Error) { throw (Error) thr; } else { throw new RuntimeException( "Unexpected exception class: " + thr.getClass().getName() + ": " + thr.getMessage(), thr); } } }