-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExtractedPDF.java
More file actions
62 lines (55 loc) · 1.67 KB
/
Copy pathExtractedPDF.java
File metadata and controls
62 lines (55 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.mindee.pdf;
import com.mindee.input.LocalInputSource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import lombok.Getter;
/**
* An extracted sub-PDF.
*/
@Getter
public class ExtractedPDF {
private final byte[] fileBytes;
private final String filename;
/**
* Default constructor.
*
* @param fileBytes PDF file as bytes.
* @param filename Name of the extracted file.
*/
public ExtractedPDF(byte[] fileBytes, String filename) {
this.fileBytes = fileBytes;
this.filename = filename;
}
/**
* Write the extracted PDF to a file.
*
* @param outputPath the output path, it may be a file or a directory.
* @throws IOException Throws if the file can't be accessed.
*/
public void writeToFile(Path outputPath) throws IOException {
if (!Files.isDirectory(outputPath)) {
throw new IllegalArgumentException("Provided path is not a directory.");
}
Files.write(outputPath.resolve(this.filename), this.fileBytes);
}
/**
* Write the extracted PDF to a file.
*
* @param outputPath the output path, it may be a file or a directory.
* @throws IOException Throws if the file can't be accessed.
*/
public void writeToFile(String outputPath) throws IOException {
writeToFile(Paths.get(outputPath));
}
/**
* Return the file in a format suitable for sending to MindeeClient for parsing.
*
* @return an instance of {@link LocalInputSource}
* @throws IOException Throws if the file can't be accessed.
*/
public LocalInputSource asInputSource() throws IOException {
return new LocalInputSource(this.fileBytes, this.filename);
}
}