gpt4 book ai didi

org.springframework.batch.item.WriteFailedException.()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-24 14:27:05 26 4
gpt4 key购买 nike

本文整理了Java中org.springframework.batch.item.WriteFailedException.<init>()方法的一些代码示例,展示了WriteFailedException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WriteFailedException.<init>()方法的具体详情如下:
包路径:org.springframework.batch.item.WriteFailedException
类名称:WriteFailedException
方法名:<init>

WriteFailedException.<init>介绍

[英]Create a new WriteFailedException based on a message.
[中]基于消息创建新的WriteFailedException。

代码示例

代码示例来源:origin: spring-projects/spring-batch

@Override
public void write(List<? extends Trade> trades) {
  for (Trade trade : trades) {
    log.debug(trade);
    dao.writeTrade(trade);
    Assert.notNull(trade.getPrice(), "price must not be null"); // There must be a price to total
    if (this.failingCustomers.contains(trade.getCustomer())) {
      throw new WriteFailedException("Something unexpected happened!");
    }
  }
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * Convenience method for clients to determine if there is any unflushed
 * data.
 *
 * @return the current size (in bytes) of unflushed buffered data
 */
public long getBufferSize() {
  if (!transactionActive()) {
    return 0L;
  }
  try {
    return getCurrentBuffer().toString().getBytes(encoding).length;
  } catch (UnsupportedEncodingException e) {
    throw new WriteFailedException("Could not determine buffer size because of unsupported encoding: " + encoding, e);
  }
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * Write the value objects and flush them to the file.
 * 
 * @param items the value object
 *
 * @throws IOException thrown if general error occurs.
 * @throws XmlMappingException thrown if error occurs during XML Mapping.
 */
@Override
public void write(List<? extends T> items) throws XmlMappingException, IOException {
  if(!this.initialized) {
    throw new WriterNotOpenException("Writer must be open before it can be written to");
  }
  currentRecordCount += items.size();
  for (Object object : items) {
    Assert.state(marshaller.supports(object.getClass()),
        "Marshaller must support the class of the marshalled object");
    Result result = createStaxResult();
    marshaller.marshal(object, result);
  }
  try {
    eventWriter.flush();
    if (forceSync) {
      channel.force(false);
    }            
  }
  catch (XMLStreamException | IOException e) {
    throw new WriteFailedException("Failed to flush the events", e);
  } 
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * Writes out a string followed by a "new line", where the format of the new
 * line separator is determined by the underlying operating system.
 * 
 * @param items list of items to be written to output stream
 * @throws Exception if an error occurs while writing items to the output stream
 */
@Override
public void write(List<? extends T> items) throws Exception {
  if (!getOutputState().isInitialized()) {
    throw new WriterNotOpenException("Writer must be open before it can be written to");
  }
  if (logger.isDebugEnabled()) {
    logger.debug("Writing to file with " + items.size() + " items.");
  }
  OutputState state = getOutputState();
  String lines = doWrite(items);
  try {
    state.write(lines);
  }
  catch (IOException e) {
    throw new WriteFailedException("Could not write data. The file may be corrupt.", e);
  }
  state.setLinesWritten(state.getLinesWritten() + items.size());
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * condition: skippable < fatal; exception is skippable
 *
 * expected: true
 */
@Test
public void testSkippableSubset_skippable() throws Exception {
  assertTrue(getSkippableSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0));
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * condition: skippable < fatal; exception is skippable
 * 
 * expected: true
 */
@Test
public void testSkippableSubset_skippable() {
  assertTrue(getSkippableSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0));
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * condition: fatal < skippable; exception is fatal
 *
 * expected: false
 */
@Test
public void testFatalSubsetFatal() throws Exception {
  assertFalse(getFatalSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0));
}

代码示例来源:origin: spring-projects/spring-batch

/**
   * condition: fatal < skippable; exception is fatal
   * 
   * expected: false
   */
  @Test
  public void testFatalSubset_fatal() {
    assertFalse(getFatalSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0));
  }
}

代码示例来源:origin: spring-projects/spring-hadoop-samples-old

/**
 * Extracts the payload as a byte array.  
 * @param message
 * @return
 */
private byte[] getItemsAsBytes(List<? extends T> items) {
  
  StringBuilder lines = new StringBuilder();
  for (T item: items) {
    lines.append(lineAggregator.aggregate(item) + lineSeparator);
  }
  try {
    return lines.toString().getBytes(this.charset);
  } catch (UnsupportedEncodingException e) {
      throw new WriteFailedException("Could not write data.", e);
  }
}

代码示例来源:origin: spring-projects/spring-hadoop-samples-old

/**
 * Extracts the payload as a byte array.  
 * @param message
 * @return
 */
private byte[] getItemsAsBytes(List<? extends T> items) {
  
  StringBuilder lines = new StringBuilder();
  for (T item: items) {
    lines.append(lineAggregator.aggregate(item) + lineSeparator);
  }
  try {
    return lines.toString().getBytes(this.charset);
  } catch (UnsupportedEncodingException e) {
      throw new WriteFailedException("Could not write data.", e);
  }
}

代码示例来源:origin: com.github.almex/raildelays-batch

@Override
public boolean doWrite(T item) throws Exception {
  T previousRow = null;
  if (item != null) {
    try {
      previousRow = rowAggregator.aggregate(item, workbook, sheetIndex, getCurrentItemIndex());
      LOGGER.trace("Previous row={}", previousRow);
    } catch (Exception e) {
      throw new WriteFailedException("We were not able to write in the Excel file", e);
    }
  }
  return previousRow == null;
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Convenience method for clients to determine if there is any unflushed
 * data.
 *
 * @return the current size (in bytes) of unflushed buffered data
 */
public long getBufferSize() {
  if (!transactionActive()) {
    return 0L;
  }
  try {
    return getCurrentBuffer().toString().getBytes(encoding).length;
  } catch (UnsupportedEncodingException e) {
    throw new WriteFailedException("Could not determine buffer size because of unsupported encoding: " + encoding, e);
  }
}

代码示例来源:origin: uk.ac.ebi.intact.dataexchange/intact-tasks

throw new WriteFailedException("You must open the writer before writing files.");

代码示例来源:origin: apache/servicemix-bundles

/**
 * Write the value objects and flush them to the file.
 * 
 * @param items the value object
 *
 * @throws IOException thrown if general error occurs.
 * @throws XmlMappingException thrown if error occurs during XML Mapping.
 */
@Override
public void write(List<? extends T> items) throws XmlMappingException, IOException {
  if(!this.initialized) {
    throw new WriterNotOpenException("Writer must be open before it can be written to");
  }
  currentRecordCount += items.size();
  for (Object object : items) {
    Assert.state(marshaller.supports(object.getClass()),
        "Marshaller must support the class of the marshalled object");
    Result result = createStaxResult();
    marshaller.marshal(object, result);
  }
  try {
    eventWriter.flush();
    if (forceSync) {
      channel.force(false);
    }            
  }
  catch (XMLStreamException | IOException e) {
    throw new WriteFailedException("Failed to flush the events", e);
  } 
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Writes out a string followed by a "new line", where the format of the new
 * line separator is determined by the underlying operating system.
 * 
 * @param items list of items to be written to output stream
 * @throws Exception if an error occurs while writing items to the output stream
 */
@Override
public void write(List<? extends T> items) throws Exception {
  if (!getOutputState().isInitialized()) {
    throw new WriterNotOpenException("Writer must be open before it can be written to");
  }
  if (logger.isDebugEnabled()) {
    logger.debug("Writing to file with " + items.size() + " items.");
  }
  OutputState state = getOutputState();
  String lines = doWrite(items);
  try {
    state.write(lines);
  }
  catch (IOException e) {
    throw new WriteFailedException("Could not write data. The file may be corrupt.", e);
  }
  state.setLinesWritten(state.getLinesWritten() + items.size());
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com