public final void doWhileLocked() throws IOException { Lock lock = this.lockRegistry.obtain(this.key); try { lock.lockInterruptibly(); try { this.whileLocked(); } finally { lock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new MessagingException("Thread was interrupted while performing task", e); } }
whileLockedProcessor.doWhileLocked(); cleanUpAfterCopy(fileToWriteTo, resultFile, originalFile); return resultFile;
public final void doWhileLocked() throws IOException { Lock lock = this.lockRegistry.obtain(this.key); try { lock.lockInterruptibly(); try { this.whileLocked(); } finally { lock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new MessagingException("Thread was interrupted while performing task", e); } }
private File handleByteArrayMessage(byte[] bytes, File originalFile, File tempFile, File resultFile, Message<?> requestMessage) throws IOException { final File fileToWriteTo = determineFileToWrite(resultFile, tempFile); boolean append = FileExistsMode.APPEND.equals(this.fileExistsMode) || FileExistsMode.APPEND_NO_FLUSH.equals(this.fileExistsMode); WhileLockedProcessor whileLockedProcessor = new WhileLockedProcessor(this.lockRegistry, fileToWriteTo.getAbsolutePath()) { @Override protected void whileLocked() throws IOException { if (append && FileWritingMessageHandler.this.newFileCallback != null && !fileToWriteTo.exists()) { FileWritingMessageHandler.this.newFileCallback.accept(fileToWriteTo, requestMessage); } writeBytesToFile(fileToWriteTo, append, bytes); } }; whileLockedProcessor.doWhileLocked(); cleanUpAfterCopy(fileToWriteTo, resultFile, originalFile); return resultFile; }
private File handleStringMessage(String content, File originalFile, File tempFile, File resultFile, Message<?> requestMessage) throws IOException { File fileToWriteTo = determineFileToWrite(resultFile, tempFile); boolean append = FileExistsMode.APPEND.equals(this.fileExistsMode) || FileExistsMode.APPEND_NO_FLUSH.equals(this.fileExistsMode); WhileLockedProcessor whileLockedProcessor = new WhileLockedProcessor(this.lockRegistry, fileToWriteTo.getAbsolutePath()) { @Override protected void whileLocked() throws IOException { if (append && FileWritingMessageHandler.this.newFileCallback != null && !fileToWriteTo.exists()) { FileWritingMessageHandler.this.newFileCallback.accept(fileToWriteTo, requestMessage); } writeStringToFile(fileToWriteTo, append, content); } }; whileLockedProcessor.doWhileLocked(); cleanUpAfterCopy(fileToWriteTo, resultFile, originalFile); return resultFile; }