-
-
Save pysoftware/8fef355890eca482052142536c5f7884 to your computer and use it in GitHub Desktop.
quiz.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Made this class fully public for next extend cases | |
* For now it's unclear is this need to split FileContent class to different ones | |
* | |
* F.e. ParsedFile could have two methods returning SimpleContent and UnicodeFreeContent | |
* And each *Content class could have unique logic in it | |
* | |
* ParsedFile is thread safe because of immutability | |
*/ | |
class FileContent { | |
private final String raw; | |
public FileContent(String rawContent) { | |
this.raw = rawContent; | |
} | |
public String text() { | |
return this.raw; | |
} | |
} | |
class ParsedFile { | |
private final InputStream fileInputStream; | |
public ParsedFile(InputStream fileInputStream) { | |
this.fileInputStream = fileInputStream; | |
} | |
public FileContent content() { | |
String content = "bytes converted to string"; | |
return new FileContent(content); | |
} | |
public FileContent contentUnicodeFree() { | |
String content = "bytes converted to string without unicode"; | |
return new FileContent(content); | |
} | |
} | |
class DefaultParsedFileUsage { | |
public static void main(String[] args) { | |
File file = new File("path"); | |
try(InputStream is = new FileInputStream(file)) { | |
ParsedFile parsedFile = new ParsedFile(is); | |
FileContent fileContent = parsedFile.content(); | |
String fileText = fileContent.text(); | |
// next code | |
} catch (IOException ioException) { | |
// logging exception | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment