Skip to content

Commit e8d8fb9

Browse files
committed
Forgot to commit
1 parent 3f782c2 commit e8d8fb9

File tree

7 files changed

+242
-1
lines changed

7 files changed

+242
-1
lines changed

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Java HTTP Server
2+
3+
This is a very simple HTTP using only java ServerSockets and Sockets
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package dev.hdprojects.HttpServer.util;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.io.FileNotFoundException;
7+
import java.io.FileReader;
8+
import java.io.IOException;
9+
10+
public class FileOpener {
11+
12+
private final static Logger LOGGER = LoggerFactory.getLogger(FileOpener.class);
13+
14+
private String filePath;
15+
private String fileContents;
16+
17+
18+
/**
19+
* Get a file as a String
20+
*
21+
* @param fileReader The fileReader object that you want read
22+
* @return The contents of the file
23+
* @throws IOException Throws an IOException if it cannot read the file
24+
*/
25+
private String getFileAsString(FileReader fileReader) throws IOException{
26+
String result = new String("");
27+
28+
int i;
29+
while ((i=fileReader.read()) != -1)
30+
result += (char) i;
31+
return result;
32+
}
33+
34+
private void openFileString() {
35+
36+
FileReader fileReader = null;
37+
38+
try {
39+
fileReader = new FileReader(filePath);
40+
} catch (FileNotFoundException e) {
41+
LOGGER.error("File not found");
42+
}
43+
44+
try {
45+
// Throws error if file is not found
46+
if (fileReader == null) throw new FileOpenerException("File Not Found");
47+
48+
// Sets file to the contents of the fileReader object
49+
else this.fileContents = getFileAsString(fileReader);
50+
} catch (IOException e) {
51+
LOGGER.error("File failed to read");
52+
}
53+
}
54+
55+
public FileOpener(String filePath) {
56+
this.filePath = filePath;
57+
58+
openFileString();
59+
60+
61+
}
62+
63+
public String getFilePath() {
64+
return filePath;
65+
}
66+
67+
public void setFilePath(String filePath) {
68+
this.filePath = filePath;
69+
openFileString();
70+
}
71+
72+
public String getFileContents() {
73+
return fileContents;
74+
}
75+
76+
public void setFileContents(String fileContents) {
77+
this.fileContents = fileContents;
78+
openFileString();
79+
}
80+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.hdprojects.HttpServer.util;
2+
3+
import java.io.IOException;
4+
5+
public class FileOpenerException extends IOException {
6+
7+
public FileOpenerException() {
8+
super();
9+
}
10+
11+
public FileOpenerException(String message) {
12+
super(message);
13+
}
14+
15+
public FileOpenerException(String message, Throwable cause) {
16+
super(message, cause);
17+
}
18+
19+
public FileOpenerException(Throwable cause) {
20+
super(cause);
21+
}
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package dev.hdprojects.website;
2+
3+
public class CssReplacer {
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package dev.hdprojects.html;
1+
package dev.hdprojects.website;
22

33
public class HtmlParser {
44

55
private String file;
66
private String contents;
7+
8+
79
}

0 commit comments

Comments
 (0)