|
|
|
@ -17,7 +17,6 @@ package org.springframework.data.mongodb.gridfs; |
|
|
|
|
|
|
|
|
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
@ -40,9 +39,6 @@ import com.mongodb.client.gridfs.model.GridFSFile; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
|
|
|
|
|
|
|
|
static final String CONTENT_TYPE_FIELD = "_contentType"; |
|
|
|
|
|
|
|
private static final ByteArrayInputStream EMPTY_INPUT_STREAM = new ByteArrayInputStream(new byte[0]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final @Nullable GridFSFile file; |
|
|
|
private final @Nullable GridFSFile file; |
|
|
|
private final String filename; |
|
|
|
private final String filename; |
|
|
|
private final Flux<DataBuffer> content; |
|
|
|
private final Flux<DataBuffer> content; |
|
|
|
@ -105,7 +101,7 @@ public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
public long contentLength() throws IOException { |
|
|
|
public long contentLength() throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
verifyExists(); |
|
|
|
verifyExists(); |
|
|
|
return file.getLength(); |
|
|
|
return getGridFSFile().getLength(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
@ -114,7 +110,7 @@ public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getFilename() throws IllegalStateException { |
|
|
|
public String getFilename() throws IllegalStateException { |
|
|
|
return filename; |
|
|
|
return this.filename; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
@ -123,7 +119,7 @@ public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean exists() { |
|
|
|
public boolean exists() { |
|
|
|
return file != null; |
|
|
|
return this.file != null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
@ -134,7 +130,7 @@ public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
public long lastModified() throws IOException { |
|
|
|
public long lastModified() throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
verifyExists(); |
|
|
|
verifyExists(); |
|
|
|
return file.getUploadDate().getTime(); |
|
|
|
return getGridFSFile().getUploadDate().getTime(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
@ -156,7 +152,7 @@ public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
|
|
|
|
|
|
|
|
Assert.state(exists(), () -> String.format("%s does not exist.", getDescription())); |
|
|
|
Assert.state(exists(), () -> String.format("%s does not exist.", getDescription())); |
|
|
|
|
|
|
|
|
|
|
|
return file.getId(); |
|
|
|
return getGridFSFile().getId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -178,7 +174,7 @@ public class ReactiveGridFsResource extends AbstractResource { |
|
|
|
if (!exists()) { |
|
|
|
if (!exists()) { |
|
|
|
return Flux.error(new FileNotFoundException(String.format("%s does not exist.", getDescription()))); |
|
|
|
return Flux.error(new FileNotFoundException(String.format("%s does not exist.", getDescription()))); |
|
|
|
} |
|
|
|
} |
|
|
|
return content; |
|
|
|
return this.content; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void verifyExists() throws FileNotFoundException { |
|
|
|
private void verifyExists() throws FileNotFoundException { |
|
|
|
|