Skip to content

Commit

Permalink
Responded to code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AyoTheDev committed Jun 18, 2023
1 parent ee9bd76 commit 034da44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.common.flogger.FluentLogger;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Optional;
import javax.inject.Inject;
Expand All @@ -30,14 +29,14 @@ public PDFConnector(@NonNull PDFConnectorOption readOption) {
public Optional<String> read() {
try {
PDDocument selectedDocument;
Optional<byte[]> bytes = readOption.getBytes();
Optional<byte[]> bytes = readOption.getFileBytes();
Optional<String> filePath = readOption.getFilePath();
if (bytes.isPresent()) {
selectedDocument = PDDocument.load(bytes.get());
} else if (filePath.isPresent()) {
selectedDocument = PDDocument.load(new File(filePath.get()));
} else {
throw new PDFConnectorOptionNotFoundException();
throw new PDFConnectorOptionNotFoundException("No suitable read option provided");
}

@Cleanup PDDocument document = selectedDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
@Data
@Builder(toBuilder = true, setterPrefix = "set")
public class PDFConnectorOption implements ConnectorOption {
@Builder.Default private Optional<String> filePath = Optional.empty();
@Builder.Default private Optional<byte[]> bytes = Optional.empty();
private String filePath;
private byte[] fileBytes;

public Optional<String> getFilePath() {
return Optional.ofNullable(filePath);
}

public Optional<byte[]> getFileBytes() {
return Optional.ofNullable(fileBytes);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ai.knowly.langtorch.connector.pdf;

public class PDFConnectorOptionNotFoundException extends RuntimeException {
public PDFConnectorOptionNotFoundException() {
super();
public PDFConnectorOptionNotFoundException(String msg) {
super(msg);
}
}

0 comments on commit 034da44

Please sign in to comment.