Skip to content

Commit

Permalink
Merge pull request #2 from fearricepudding/hashtable
Browse files Browse the repository at this point in the history
WIP Adding hash table
  • Loading branch information
fearricepudding authored Apr 7, 2021
2 parents 84e059e + 0fde82f commit 3968265
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 286 deletions.
69 changes: 0 additions & 69 deletions Examples/PHP/index.php

This file was deleted.

2 changes: 0 additions & 2 deletions Examples/curl/delete

This file was deleted.

5 changes: 0 additions & 5 deletions Examples/curl/get

This file was deleted.

4 changes: 0 additions & 4 deletions Examples/curl/put

This file was deleted.

38 changes: 0 additions & 38 deletions Examples/node/index.js

This file was deleted.

11 changes: 0 additions & 11 deletions Examples/node/package.json

This file was deleted.

Binary file removed bin/Server.class
Binary file not shown.
25 changes: 0 additions & 25 deletions pom.xml

This file was deleted.

Binary file added release/java-key-store.jar
Binary file not shown.
Binary file removed release/keystore.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion release/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
2.1.0
32 changes: 7 additions & 25 deletions src/fearricepudding/Server.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import com.google.gson.Gson;
import fearricepudding.Storage;

public class Server implements Runnable {
Expand All @@ -26,18 +25,12 @@ public class Server implements Runnable {

/**
* Generate socket
* s
* @param c
*/
public Server(Socket c) {
connect = c;
}

/**
* Starting point
*
* @param args
*/
public static void main(String[] args) {
try {
if (args[0] != null) {
Expand Down Expand Up @@ -70,7 +63,6 @@ public static void main(String[] args) {

/**
* Get version string from version file
*
* @return version string
*/
public static String getVersion() {
Expand Down Expand Up @@ -104,8 +96,7 @@ public void run() {
int postDataI = -1;
while ((line = in.readLine()) != null && (line.length() != 0)) {
if (line.indexOf("Content-Length:") > -1) {
postDataI = Integer.valueOf(
line.substring(line.indexOf("Content-Length:") + 16,line.length())).intValue();
postDataI = Integer.valueOf(line.substring(line.indexOf("Content-Length:") + 16,line.length())).intValue();
}
}
postData = "";
Expand All @@ -115,8 +106,7 @@ public void run() {
postData = new String(charArray);
}
key = parse.nextToken().toLowerCase().substring(1);
Storage data = new Storage(key);
Gson gson = new Gson();
Storage data = new Storage();
contentMimeType = "application/json";
out.println("HTTP/1.1 200 OK");
out.println("Server: tinykeystore");
Expand All @@ -133,37 +123,29 @@ public void run() {
System.out.println("Request key: "+key);
System.out.println("post: "+postData);
}
String response = "";
if(method.equals("GET")) {
String response = null;
// *** GET METHOD *** //
data.find(key);
response = gson.toJson(data);
dataOut.write(response.getBytes(), 0, response.getBytes().length);
dataOut.flush();
response = data.get(key);
}else if(method.equals("PUT")) {
// *** PUT METHOD *** //
String response = null;
boolean succ = data.store(postData, key, ALLOW_OVERWRITE);
if(succ) {
data.find(key);
response = gson.toJson(data);
response = data.get(key);
} else {
response = "{data:\"Key exists, overwrite disabled\", status:\"error\"}";
}
dataOut.write(response.getBytes(), 0, response.getBytes().length);
dataOut.flush();
}else if(method.contentEquals("DELETE")) {
// *** DELETE METHOD *** //
String response = null;
boolean succ = data.delete(key);
if(succ) {
response = "{status:\"ok\"}";
}else {
response = "{status:\"error\"}";
}
dataOut.write(response.getBytes(), 0, response.getBytes().length);
dataOut.flush();
}
dataOut.write(response.getBytes(), 0, response.getBytes().length);
dataOut.flush();
} catch (IOException e) {
System.out.println("Genral run error");
e.printStackTrace();
Expand Down
Loading

0 comments on commit 3968265

Please sign in to comment.