本文整理汇总了Java中org.springframework.batch.item.ItemStreamException类的典型用法代码示例。如果您正苦于以下问题:Java ItemStreamException类的具体用法?Java ItemStreamException怎么用?Java ItemStreamException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ItemStreamException类属于org.springframework.batch.item包,在下文中一共展示了ItemStreamException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void open(ExecutionContext executionContext) throws
ItemStreamException {
if (executionContext == null) {
throw new IllegalArgumentException();
}
if (executionContext.containsKey(IDS_NUMBER)) {
number = executionContext.getInt(IDS_NUMBER);
count = executionContext.getInt(CURRENT_ID_COUNT);
ids = new String[number];
for (int i = 0; i < number; i++) {
ids[i] = executionContext.getString(LIST_ID + i);
}
} else {
ids = loadListIds();
number = ids.length;
count = 0;
}
}
示例2: update
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void update(ExecutionContext executionContext) throws
ItemStreamException {
/* Clear context */
for (Entry<String, Object> entry : executionContext.entrySet()) {
String key = entry.getKey();
executionContext.remove(key);
}
executionContext.putInt(IDS_NUMBER, number);
executionContext.putInt(CURRENT_ID_COUNT, count);
for (int i = 0; i < number; i++) {
executionContext.putString(LIST_ID + i, ids[i]);
}
}
示例3: update
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void update(ExecutionContext executionContext) {
if (state == null) {
throw new ItemStreamException(
"ItemStream not open or already closed.");
}
Assert.notNull(executionContext, "ExecutionContext must not be null");
if (saveState) {
try {
executionContext.putLong(
getExecutionContextKey(RESTART_DATA_NAME),
state.position());
} catch (IOException e) {
throw new ItemStreamException(
"ItemStream does not return current position properly",
e);
}
executionContext.putLong(
getExecutionContextKey(WRITTEN_STATISTICS_NAME),
state.jsonObjectsWritten);
}
}
示例4: getOutputState
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
private OutputState getOutputState() {
if (state == null) {
File file;
try {
file = resource.getFile();
} catch (IOException e) {
throw new ItemStreamException(
"Could not convert resource to file: [" + resource
+ "]", e);
}
Assert.state(!file.exists() || file.canWrite(),
"Resource is not writable: [" + resource + "]");
state = new OutputState();
state.setDeleteIfExists(shouldDeleteIfExists);
state.setAppendAllowed(append);
state.setEncoding(encoding);
}
return state;
}
示例5: close
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
/**
* Close the open resource and reset counters.
*/
public void close() {
initialized = false;
restarted = false;
try {
if (outputBufferedWriter != null) {
outputBufferedWriter.close();
}
} catch (IOException ioe) {
throw new ItemStreamException(
"Unable to close the the ItemWriter", ioe);
} finally {
if (!transactional) {
closeStream();
}
}
}
示例6: open
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
ResponseEntity<String> response= restTemplate.getForEntity(uri,String.class);
if (!response.getStatusCode().equals(HttpStatus.OK)) {
throw new ItemStreamException(response.getStatusCode() + " HTTP response is returned");
};
MediaType type = response.getHeaders().getContentType();
if (MediaType.APPLICATION_JSON.equals(type)) {
jsonString = response.getBody();
Boolean isJson = isStringValidJSON(jsonString);
if (isJson){
// create an ObjectMapper instance.
ObjectMapper mapper = new ObjectMapper();
// use the ObjectMapper to read the json string and create a tree
try {
nodeElements = mapper.readTree(jsonString);
iterator = nodeElements.fieldNames();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
示例7: open
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
if (!response.getStatusCode().equals(HttpStatus.OK)) {
throw new ItemStreamException(response.getStatusCode() + " HTTP response is returned");
}
;
MediaType type = response.getHeaders().getContentType();
if (MediaType.APPLICATION_XML.equals(type) ||
MediaType.APPLICATION_ATOM_XML.equals(type) ||
MediaType.APPLICATION_XHTML_XML.equals(type) ||
MediaType.APPLICATION_RSS_XML.equals(type) ||
"text/xml".equals(type.toString())) {
SAXBuilder jdomBuilder = new SAXBuilder();
try {
Document document = jdomBuilder.build(new StringReader(response.getBody()));
ElementFilter ef = new ElementFilter(aggregateRecordElement);
aggregateRecordElementItr = document.getRootElement().getDescendants(ef);
} catch (Exception ex) {
throw new ItemStreamException(ex);
}
}
}
示例8: open
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
if (isDataMovementSdk) {
dataMovementManager = client.newDataMovementManager();
batcher = dataMovementManager.newWriteBatcher();
batcher
.withBatchSize(getBatchSize())
.withThreadCount(getThreadCount());
if (serverTransform != null) {
batcher.withTransform(serverTransform);
}
if (this.writeBatchlistener != null) {
batcher.onBatchSuccess(this.writeBatchlistener);
}
if (this.writeFailureListener != null) {
batcher.onBatchFailure(writeFailureListener);
}
} else {
batchWriter = new RestBatchWriter(client);
if (serverTransform != null) {
batchWriter.setServerTransform(serverTransform);
batchWriter.setContentFormat(contentFormat == null ? Format.XML : contentFormat);
}
batchWriter.initialize();
}
}
示例9: open
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Override
public void open(ExecutionContext sExecutionContext) throws ItemStreamException {
String aFullPath = null;
try {
baseURI = new URI(getAlfrescoService().getWebappAddress()).resolve(WEBDAV_PATH);
aFullPath = getWebDavDirectoryURI(baseURI.getPath() + path).getPath();
} catch (URISyntaxException e) {
throw new ItemStreamException(e);
}
currentDirPath = sExecutionContext.getString(CONTEXT_KEY_CURRENTPATH, aFullPath);
Object aCurrentIndexes = sExecutionContext.get(CONTEXT_KEY_CURRENTINDEXES);
if (aCurrentIndexes == null) {
currentIndexes = new ArrayDeque<Integer>();
currentIndexes.addFirst(0);
} else {
Integer[] aArray = (Integer[]) aCurrentIndexes;
currentIndexes = new ArrayDeque<Integer>(Arrays.asList(aArray));
}
sardine = getAlfrescoService().startWebDavSession();
}
示例10: testReadNotExistsStrict
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
@Test
public void testReadNotExistsStrict() throws Exception {
exception.expect(ItemStreamException.class);
IdentityResourceAwareItemReaderItemStream aReader = new IdentityResourceAwareItemReaderItemStream();
aReader.setName("testReader");
aReader.setStrict(true);
Resource aResource = mock(Resource.class);
when(aResource.getFilename()).thenReturn("file1");
when(aResource.getDescription()).thenReturn("file1");
when(aResource.exists()).thenReturn(false);
aReader.setResource(aResource);
aReader.open(new ExecutionContext());
assertNull(aReader.read());
aReader.close();
}
示例11: open
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
/**
* Figure out which resource to start with in case of restart, open the delegate and restore
* delegate's position in the resource.
*/
@SuppressWarnings("unchecked")
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
this.currentCount = 0;
this.entityIterator = ENTITIES.iterator();
if (executionContext.containsKey(getExecutionContextKey(ENTITY_KEY))) {
String entityClassName = executionContext.getString(getExecutionContextKey(ENTITY_KEY));
while (this.entityIterator.hasNext()) {
Class<?> entityClass = this.entityIterator.next();
if (entityClassName.equals(entityClass.getName())) {
this.currentEntityClass = (Class<Object>) entityClass;
break;
}
}
}
if (this.currentEntityClass == null) {
this.entityIterator = ENTITIES.iterator();
this.currentEntityClass = (Class<Object>) this.entityIterator.next();
}
this.reader = createNextEntityReader();
}
示例12: update
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
/**
* state의 상태를 갱신하고 다음에 쓰여질 position을 지정
* @see ItemStream#update(ExecutionContext)
*/
public void update(ExecutionContext executionContext) {
if (state == null) {
throw new ItemStreamException(
"ItemStream not open or already closed.");
}
Assert.notNull(executionContext, "ExecutionContext must not be null");
if (saveState) {
try {
executionContext.putLong(getKey(RESTART_DATA_NAME),
state.position());
} catch (IOException e) {
throw new ItemStreamException(
"ItemStream does not return current position properly",
e);
}
executionContext.putLong(getKey(WRITTEN_STATISTICS_NAME),
state.linesWritten);
}
}
示例13: getOutputState
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
/**
* 파일을 쓰기 위한 OutputState 의 상태를 설정하여 를 넘겨줌
* @return
*/
private OutputState getOutputState() {
if (state == null) {
File file;
try {
file = resource.getFile();
} catch (IOException e) {
throw new ItemStreamException(
"Could not convert resource to file: [" + resource
+ "]", e);
}
Assert.state(!file.exists() || file.canWrite(),
"Resource is not writable: [" + resource + "]");
state = new OutputState();
state.setDeleteIfExists(shouldDeleteIfExists);
state.setAppendAllowed(append);
state.setEncoding(encoding);
}
return (OutputState) state;
}
示例14: close
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
/**
* outputBufferedWriter를 닫는다
*
*/
public void close() {
initialized = false;
restarted = false;
try {
if (outputBufferedWriter != null) {
outputBufferedWriter.close();
}
} catch (IOException ioe) {
throw new ItemStreamException(
"Unable to close the the ItemWriter", ioe);
} finally {
if (!transactional) {
closeStream();
}
}
}
示例15: getBufferedWriter
import org.springframework.batch.item.ItemStreamException; //导入依赖的package包/类
/**
* BufferedWriter를 가져 온다.
*/
private Writer getBufferedWriter(FileChannel fileChannel,
String encoding) {
try {
Writer writer = Channels.newWriter(fileChannel, encoding);
if (transactional) {
return new TransactionAwareBufferedWriter(writer,
new Runnable() {
public void run() {
closeStream();
}
});
} else {
return new BufferedWriter(writer);
}
} catch (UnsupportedCharsetException ucse) {
throw new ItemStreamException(
"Bad encoding configuration for output file "
+ fileChannel, ucse);
}
}