Example usage for org.springframework.integration.file FileHeaders SET_MODIFIED

List of usage examples for org.springframework.integration.file FileHeaders SET_MODIFIED

Introduction

In this page you can find the example usage for org.springframework.integration.file FileHeaders SET_MODIFIED.

Prototype

String SET_MODIFIED

To view the source code for org.springframework.integration.file FileHeaders SET_MODIFIED.

Click Source Link

Usage

From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java

@Test
public void stringPayloadCopiedToNewFile() throws Exception {
    long lastModified = 1234000L;
    Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT)
            .setHeader(FileHeaders.SET_MODIFIED, lastModified).build();
    QueueChannel output = new QueueChannel();
    handler.setCharset(DEFAULT_ENCODING);
    handler.setOutputChannel(output);//  w  ww .j  a va 2  s  .com
    handler.setPreserveTimestamp(true);
    handler.handleMessage(message);
    Message<?> result = output.receive(0);
    assertFileContentIsMatching(result);
    assertLastModifiedIs(result, lastModified);
}

From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java

@Test
public void replaceIfDifferent() throws IOException {
    QueueChannel output = new QueueChannel();
    this.handler.setOutputChannel(output);
    this.handler.setPreserveTimestamp(true);
    this.handler.setFileExistsMode(FileExistsMode.REPLACE_IF_MODIFIED);
    this.handler.handleMessage(
            MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "replaceIfDifferent.txt")
                    .setHeader(FileHeaders.SET_MODIFIED, 42_000_000).build());
    Message<?> result = output.receive(0);
    assertFileContentIs(result, "foo");
    assertLastModifiedIs(result, 42_000_000);
    this.handler.handleMessage(
            MessageBuilder.withPayload("bar").setHeader(FileHeaders.FILENAME, "replaceIfDifferent.txt")
                    .setHeader(FileHeaders.SET_MODIFIED, 42_000_000).build());
    result = output.receive(0);//from  w  w  w  . j a v  a 2  s  .c o m
    assertFileContentIs(result, "foo"); // no overwrite - timestamp same
    assertLastModifiedIs(result, 42_000_000);
    this.handler.handleMessage(
            MessageBuilder.withPayload("bar").setHeader(FileHeaders.FILENAME, "replaceIfDifferent.txt")
                    .setHeader(FileHeaders.SET_MODIFIED, 43_000_000).build());
    result = output.receive(0);
    assertFileContentIs(result, "bar");
    assertLastModifiedIs(result, 43_000_000);
}