Created
July 29, 2022 10:47
-
-
Save kolebakin/91468f93f4103593d3a9dc25840ed026 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * This class is thread safe. | |
| */ | |
| @AllArgsConstructor | |
| @NoArgsConstructor | |
| public class Parser { | |
| private File file; | |
| public synchronized void setFile(File f) { | |
| file = f; | |
| } | |
| public synchronized File getFile() { | |
| return file; | |
| } | |
| public String getContent() { | |
| StringBuilder output = ""; | |
| int data; | |
| try(InputStream i = new FileInputStream(file)) { | |
| while ((data = i.read()) > 0) { | |
| output.append((char) data); | |
| } | |
| } catch(IOException e) { | |
| sout("Message") | |
| } | |
| return output; | |
| } | |
| public String getContentWithoutUnicode() { | |
| InputStream i = new FileInputStream(file); | |
| String output = ""; | |
| int data; | |
| while ((data = i.read()) > 0) { | |
| if (data < 0x80) { | |
| output += (char) data; | |
| } | |
| } | |
| return output; | |
| } | |
| public void saveContent(String content) { // add try with resources | |
| OutputStream o = new FileOutputStream(file); | |
| for (int i = 0; i < content.length(); i ++) { | |
| o.write(content.charAt(i)); | |
| } | |
| } | |
| } | |
| ArrayList() vs LinkedList | |
| for ... 10^9 | |
| arr.add(i); | |
| Rapsberry PI + JVM + 1 Mb RAM | |
| HashMap vs TreeMap | |
| 10^9 | |
| for(...10^9) | |
| map.put(k, v); | |
| @Entity | |
| class Table { | |
| @OneToMany | |
| Collection<Element> elements; | |
| } | |
| @Entity | |
| class Element { | |
| } | |
| Table t = repostiroty.getById(....); | |
| t.getElements().forEach(sout::); | |
| EAGER | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment