@Override public void write(List<? extends T> items) throws Exception { if (!opened) { File file = setResourceToDelegate(); // create only if write is called file.createNewFile(); Assert.state(file.canWrite(), "Output resource " + file.getAbsolutePath() + " must be writable"); delegate.open(new ExecutionContext()); opened = true; } delegate.write(items); currentResourceItemCount += items.size(); if (currentResourceItemCount >= itemCountLimitPerResource) { delegate.close(); resourceIndex++; currentResourceItemCount = 0; setResourceToDelegate(); opened = false; } }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { super.open(executionContext); resourceIndex = executionContext.getInt(getExecutionContextKey(RESOURCE_INDEX_KEY), 1); currentResourceItemCount = executionContext.getInt(getExecutionContextKey(CURRENT_RESOURCE_ITEM_COUNT), 0); try { setResourceToDelegate(); } catch (IOException e) { throw new ItemStreamException("Couldn't assign resource", e); } if (executionContext.containsKey(getExecutionContextKey(CURRENT_RESOURCE_ITEM_COUNT))) { // It's a restart delegate.open(executionContext); opened = true; } else { opened = false; } }
private void writeAll(List<? extends T> items) throws Exception { try { writer.open(executionContext); writer.write(items); LOGGER.debug("Written {} items", items.size()); } finally { writer.close(); } }
@Override public void write(List<? extends ExcelRow> items) throws Exception { if (!initialized && items.size() > 0) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String suffix = format.format(items.get(0).getDate()); File file = ExcelFileUtils.getFile(new File(directoryPath), fileName, suffix, fileExtension); delegate.setResource(new FileSystemResource(file)); delegate.open(executionContext); initialized = true; } delegate.write(items); }
@Override public void write(List<? extends T> items) throws Exception { if (!opened) { File file = setResourceToDelegate(); // create only if write is called file.createNewFile(); Assert.state(file.canWrite(), "Output resource " + file.getAbsolutePath() + " must be writable"); delegate.open(new ExecutionContext()); opened = true; } delegate.write(items); currentResourceItemCount += items.size(); if (currentResourceItemCount >= itemCountLimitPerResource) { delegate.close(); resourceIndex++; currentResourceItemCount = 0; setResourceToDelegate(); opened = false; } }
@Override protected void doOpen() throws Exception { if (executionContext.containsKey(getExecutionContextKey(RESOURCE_KEY))) { resource = new FileSystemResource(executionContext.getString(getExecutionContextKey(RESOURCE_KEY), "")); // It's a restart delegate.open(executionContext); delegate.setResource(resource); // We don't have to create the resource opened = true; LOGGER.trace("Stream is opened"); } else { opened = false; LOGGER.trace("Stream is not opened yet"); } }
delegate.open(executionContext); opened = true;
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { super.open(executionContext); resourceIndex = executionContext.getInt(getExecutionContextKey(RESOURCE_INDEX_KEY), 1); currentResourceItemCount = executionContext.getInt(getExecutionContextKey(CURRENT_RESOURCE_ITEM_COUNT), 0); try { setResourceToDelegate(); } catch (IOException e) { throw new ItemStreamException("Couldn't assign resource", e); } if (executionContext.containsKey(getExecutionContextKey(CURRENT_RESOURCE_ITEM_COUNT))) { // It's a restart delegate.open(executionContext); opened = true; } else { opened = false; } }