Change Resource to WritableResource in file-based item writers

Resolves #756
This commit is contained in:
Mahmoud Ben Hassine
2022-04-13 11:17:47 +02:00
parent 74e8caa368
commit 5bce15288a
16 changed files with 73 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,15 +19,15 @@ package org.springframework.batch.item.file;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamWriter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
/**
* Interface for {@link ItemWriter}s that implement {@link ItemStream} and write
* output to {@link Resource}.
* output to {@link WritableResource}.
*
* @author Robert Kasanicky
*/
public interface ResourceAwareItemWriterItemStream<T> extends ItemStreamWriter<T> {
void setResource(Resource resource);
void setResource(WritableResource resource);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ import org.springframework.batch.item.file.transform.DelimitedLineAggregator;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.item.file.transform.FormatterLineAggregator;
import org.springframework.batch.item.file.transform.LineAggregator;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;
/**
@@ -48,7 +48,7 @@ public class FlatFileItemWriterBuilder<T> {
protected Log logger = LogFactory.getLog(getClass());
private Resource resource;
private WritableResource resource;
private boolean forceSync = false;
@@ -108,13 +108,13 @@ public class FlatFileItemWriterBuilder<T> {
}
/**
* The {@link Resource} to be used as output.
* The {@link WritableResource} to be used as output.
*
* @param resource the output of the writer.
* @return The current instance of the builder.
* @see FlatFileItemWriter#setResource(Resource)
* @see FlatFileItemWriter#setResource(WritableResource)
*/
public FlatFileItemWriterBuilder<T> resource(Resource resource) {
public FlatFileItemWriterBuilder<T> resource(WritableResource resource) {
this.resource = resource;
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,13 @@ import java.util.Iterator;
import java.util.List;
import org.springframework.batch.item.support.AbstractFileItemWriter;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Item writer that writes data in json format to an output file. The location
* of the output file is defined by a {@link Resource} and must represent a
* of the output file is defined by a {@link WritableResource} and must represent a
* writable file. Items are transformed to json format using a
* {@link JsonObjectMarshaller}. Items will be enclosed in a json array as follows:
*
@@ -61,7 +61,7 @@ public class JsonFileItemWriter<T> extends AbstractFileItemWriter<T> {
* @param resource to write json data to
* @param jsonObjectMarshaller used to marshal object into json representation
*/
public JsonFileItemWriter(Resource resource, JsonObjectMarshaller<T> jsonObjectMarshaller) {
public JsonFileItemWriter(WritableResource resource, JsonObjectMarshaller<T> jsonObjectMarshaller) {
Assert.notNull(resource, "resource must not be null");
Assert.notNull(jsonObjectMarshaller, "json object marshaller must not be null");
setResource(resource);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import org.springframework.batch.item.file.FlatFileFooterCallback;
import org.springframework.batch.item.file.FlatFileHeaderCallback;
import org.springframework.batch.item.json.JsonFileItemWriter;
import org.springframework.batch.item.json.JsonObjectMarshaller;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;
/**
@@ -32,7 +32,7 @@ import org.springframework.util.Assert;
*/
public class JsonFileItemWriterBuilder<T> {
private Resource resource;
private WritableResource resource;
private JsonObjectMarshaller<T> jsonObjectMarshaller;
private FlatFileHeaderCallback headerCallback;
private FlatFileFooterCallback footerCallback;
@@ -119,13 +119,13 @@ public class JsonFileItemWriterBuilder<T> {
}
/**
* The {@link Resource} to be used as output.
* The {@link WritableResource} to be used as output.
*
* @param resource the output of the writer.
* @return The current instance of the builder.
* @see JsonFileItemWriter#setResource(Resource)
* @see JsonFileItemWriter#setResource(WritableResource)
*/
public JsonFileItemWriterBuilder<T> resource(Resource resource) {
public JsonFileItemWriterBuilder<T> resource(WritableResource resource) {
this.resource = resource;
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,13 +41,13 @@ import org.springframework.batch.item.file.ResourceAwareItemWriterItemStream;
import org.springframework.batch.item.util.FileUtils;
import org.springframework.batch.support.transaction.TransactionAwareBufferedWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;
/**
* Base class for item writers that write data to a file or stream.
* This class provides common features like restart, force sync, append etc.
* The location of the output file is defined by a {@link Resource} which must
* The location of the output file is defined by a {@link WritableResource} which must
* represent a writable file.<br>
*
* Uses buffered writer to improve performance.<br>
@@ -81,7 +81,7 @@ public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWr
private static final String RESTART_DATA_NAME = "current.count";
private Resource resource;
private WritableResource resource;
protected OutputState state = null;
@@ -128,12 +128,12 @@ public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWr
}
/**
* Setter for resource. Represents a file that can be written.
* Setter for a writable resource. Represents a file that can be written.
*
* @param resource the resource to be written to
*/
@Override
public void setResource(Resource resource) {
public void setResource(WritableResource resource) {
this.resource = resource;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ import org.springframework.batch.item.xml.stax.UnclosedElementCollectingEventWri
import org.springframework.batch.item.xml.stax.UnopenedElementClosingEventWriter;
import org.springframework.batch.support.transaction.TransactionAwareBufferedWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.XmlMappingException;
@@ -103,7 +103,7 @@ ResourceAwareItemWriterItemStream<T>, InitializingBean {
private static final String WRITE_STATISTICS_NAME = "record.count";
// file system resource
private Resource resource;
private WritableResource resource;
// xml marshaller
private Marshaller marshaller;
@@ -177,7 +177,7 @@ ResourceAwareItemWriterItemStream<T>, InitializingBean {
* @param resource the output file
*/
@Override
public void setResource(Resource resource) {
public void setResource(WritableResource resource) {
this.resource = resource;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ import java.util.Map;
import org.springframework.batch.item.xml.StaxEventItemWriter;
import org.springframework.batch.item.xml.StaxWriterCallback;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.oxm.Marshaller;
import org.springframework.util.Assert;
@@ -34,7 +34,7 @@ import org.springframework.util.Assert;
*/
public class StaxEventItemWriterBuilder<T> {
private Resource resource;
private WritableResource resource;
private Marshaller marshaller;
@@ -80,13 +80,13 @@ public class StaxEventItemWriterBuilder<T> {
}
/**
* The {@link Resource} to be used as output.
* The {@link WritableResource} to be used as output.
*
* @param resource the output from the writer
* @return the current instance of the builder.
* @see StaxEventItemWriter#setResource(Resource)
* @see StaxEventItemWriter#setResource(WritableResource)
*/
public StaxEventItemWriterBuilder<T> resource(Resource resource) {
public StaxEventItemWriterBuilder<T> resource(WritableResource resource) {
this.resource = resource;
return this;