@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Test public void nonClosingInputStream() throws Exception { InputStream source = mock(InputStream.class); InputStream nonClosing = StreamUtils.nonClosing(source); nonClosing.read(); nonClosing.read(bytes); nonClosing.read(bytes, 1, 2); nonClosing.close(); InOrder ordered = inOrder(source); ordered.verify(source).read(); ordered.verify(source).read(bytes, 0, bytes.length); ordered.verify(source).read(bytes, 1, 2); ordered.verify(source, never()).close(); }
@Test public void nonClosingOutputStream() throws Exception { OutputStream source = mock(OutputStream.class); OutputStream nonClosing = StreamUtils.nonClosing(source); nonClosing.write(1); nonClosing.write(bytes); nonClosing.write(bytes, 1, 2); nonClosing.close(); InOrder ordered = inOrder(source); ordered.verify(source).write(1); ordered.verify(source).write(bytes, 0, bytes.length); ordered.verify(source).write(bytes, 1, 2); ordered.verify(source, never()).close(); } }
private void extractFromStream(ZipInputStream zipStream, boolean overwrite, File outputFolder) throws IOException { ZipEntry entry = zipStream.getNextEntry(); while (entry != null) { File file = new File(outputFolder, entry.getName()); if (file.exists() && !overwrite) { throw new ReportableException((file.isDirectory() ? "Directory" : "File") + " '" + file.getName() + "' already exists. Use --force if you want to overwrite or " + "specify an alternate location."); } if (!entry.isDirectory()) { FileCopyUtils.copy(StreamUtils.nonClosing(zipStream), new FileOutputStream(file)); } else { file.mkdir(); } zipStream.closeEntry(); entry = zipStream.getNextEntry(); } }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
@Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { if (this.body == null) { if (this.outputStreaming) { long contentLength = headers.getContentLength(); if (contentLength >= 0) { this.connection.setFixedLengthStreamingMode(contentLength); } else { this.connection.setChunkedStreamingMode(this.chunkSize); } } SimpleBufferingClientHttpRequest.addHeaders(this.connection, headers); this.connection.connect(); this.body = this.connection.getOutputStream(); } return StreamUtils.nonClosing(this.body); }
memJsonDB.set("/", nonClosing(zis)); changeEvents.addAll(importModels(sec, modelExport, memJsonDB)); memJsonDB.close();