Skip to content

Commit 2235ad9

Browse files
committed
moar
1 parent 6542304 commit 2235ad9

File tree

10 files changed

+155
-56
lines changed

10 files changed

+155
-56
lines changed

Diff for: SNXj_90/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ targetCompatibility = JavaVersion.VERSION_11
2323

2424
dependencies {
2525
implementation 'com.github.cekvenich:SNX:0.0.102'
26-
26+
implementation 'io.minio:minio:6.0.11'
27+
2728
}
2829
application {
2930
// Define the main class for the application.

Diff for: SNXj_90/src/main/java/org/SNXex/db/S3.java

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package org.SNXex.db;
2+
3+
import java.io.BufferedReader;
4+
import java.io.ByteArrayInputStream;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
7+
import java.util.ArrayList;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.stream.Collectors;
12+
13+
import io.minio.MinioClient;
14+
import io.minio.Result;
15+
import io.minio.errors.MinioException;
16+
import io.minio.messages.Item;
17+
18+
import org.apache.SNX.util.JUtil;
19+
20+
public class S3 {
21+
22+
// arn:aws:s3:::snx01
23+
24+
static MinioClient _mclient;
25+
26+
static String _bucket = "s3s";
27+
28+
public static void main(String[] args) throws Throwable {
29+
30+
String server = "https://s3.wasabisys.com";
31+
String access_key = "LUYU20154833CM4L57P8";
32+
String secret_key = "oKZmf7b6qmXwydFDqvm7hEGHnYVObZlN9lMtEDLD";
33+
34+
_mclient = new MinioClient(server, access_key, secret_key);
35+
36+
String prefix = "Monday/NY";
37+
Map row = new HashMap();
38+
row.put("a", "A");
39+
row.put("b", "B");
40+
put(prefix, row);
41+
// second row;
42+
put(prefix, row);
43+
44+
45+
System.out.println(find(prefix));
46+
}
47+
48+
static protected List<String> find(String prefix) throws Throwable {
49+
Iterable<Result<Item>> iter = _mclient.listObjects(_bucket, prefix);
50+
List<String> lst = new ArrayList();
51+
for (Result<Item> result : iter) {
52+
Item item = result.get();
53+
lst.add(item.objectName());
54+
}
55+
56+
return lst;
57+
}
58+
59+
static protected int getKeyPosition(String prefixPlusKey) {
60+
return prefixPlusKey.lastIndexOf('/');
61+
}
62+
63+
/**
64+
* Auto generates they, you only pass the prefix
65+
*/
66+
static protected void put(String prefix, Map m) throws Throwable {
67+
String s = JUtil.toJ(m);
68+
InputStream ins = toIns(s);
69+
String key = "";
70+
_mclient.putObject(_bucket, prefix + "/" + key, ins, "application/octet-stream");
71+
}
72+
73+
static protected void remove(String prefixPlusKey) throws Throwable {
74+
_mclient.removeObject(_bucket, prefixPlusKey);
75+
}
76+
77+
/**
78+
* Gets an InputStream stored as JSON: Map
79+
*/
80+
static protected Map getAsMap(String prefixPlusKey) throws Throwable {
81+
InputStream ins = _mclient.getObject(_bucket, prefixPlusKey);
82+
String s = toStr(ins);
83+
84+
return JUtil.toMap(s);
85+
}
86+
87+
static public String toStr(InputStream ins) {
88+
return new BufferedReader(new InputStreamReader(ins)).lines().collect(Collectors.joining("\n"));
89+
}
90+
91+
static public InputStream toIns(String str) throws Throwable {
92+
return new ByteArrayInputStream(str.getBytes("UTF-8"));
93+
}// ()
94+
95+
}// class

Diff for: deleted/src/main/java/org/apache/SNX/util/HUtil.java renamed to deleted/src/main/java/org/apache/SNX/util/HNetUtil.java

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.apache.SNX.util;
22

3+
import java.net.DatagramSocket;
4+
import java.net.InetAddress;
35
import java.nio.charset.StandardCharsets;
46
import java.util.List;
57
import java.util.Map;
@@ -9,11 +11,11 @@
911
import org.apache.hc.core5.http.NameValuePair;
1012
import org.apache.hc.core5.net.URLEncodedUtils;
1113

12-
public class HUtil {
14+
public class HNetUtil {
1315

1416
public static final String OK = "OK";
1517

16-
public static Map<String, String> getQS(final String uri_) {
18+
public static Map<String, String> qsToMap(final String uri_) {
1719
if (!uri_.contains("?"))
1820
return null;
1921
String uri = uri_.split("\\?")[1];
@@ -23,10 +25,6 @@ public static Map<String, String> getQS(final String uri_) {
2325
return qs;
2426
}
2527

26-
public static String getPath(String url) {
27-
return url.split("\\?")[0];
28-
}
29-
3028
public static String mapToQs(Map<String, Object> map) {
3129
if (map == null || map.size() < 1)
3230
return "";
@@ -46,4 +44,28 @@ public static String mapToQs(Map<String, Object> map) {
4644
return string.toString();
4745
}
4846

47+
protected static String _localHost;
48+
49+
public static synchronized String getLocalHost() {
50+
if (_localHost != null)
51+
return _localHost;
52+
53+
String h = null;
54+
try {
55+
final DatagramSocket socket = new DatagramSocket();
56+
57+
socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
58+
h = socket.getLocalAddress().getHostAddress();
59+
socket.close();
60+
} catch (Throwable e) {
61+
System.out.println(e.getMessage());
62+
}
63+
_localHost = h;
64+
return _localHost;
65+
}
66+
67+
public static String getPath(String url) {
68+
return url.split("\\?")[0];
69+
}
70+
4971
}

Diff for: deleted/src/main/java/org/apache/SNX/util/JUtil.java renamed to deleted/src/main/java/org/apache/SNX/util/JACodecUtil.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.apache.SNX.util;
22

3+
import java.nio.charset.StandardCharsets;
34
import java.util.List;
45
import java.util.Map;
56

@@ -8,7 +9,7 @@
89
import org.json.simple.parser.JSONParser;
910
import org.json.simple.parser.ParseException;
1011

11-
public class JUtil {
12+
public class JACodecUtil {
1213
static JSONParser _parser = new JSONParser();
1314

1415
static public String toJ(List lst) {
@@ -23,14 +24,28 @@ static public String toJ(Map m) {
2324
return obj.toJSONString();
2425
}
2526

26-
static public Map toMap(String j) throws ParseException {
27-
Object obj = _parser.parse(j);
27+
static public Map toMap(String s) throws ParseException {
28+
Object obj = _parser.parse(s);
2829
return (JSONObject) obj;
2930
}
3031

31-
static public List toLst(String j) throws ParseException {
32-
Object obj = _parser.parse(j);
32+
static public List toLst(String s) throws ParseException {
33+
Object obj = _parser.parse(s);
3334
return (JSONArray) obj;
3435
}
3536

37+
public static byte[] toBA8(String str) {
38+
return str.getBytes(StandardCharsets.UTF_8);
39+
}
40+
41+
/**
42+
* Convert to String UT8
43+
*
44+
* @param ba
45+
* @return
46+
*/
47+
public static String toStr8(byte[] ba) {
48+
return new String(ba, StandardCharsets.UTF_8);
49+
}
50+
3651
}// class

Diff for: deleted/src/main/java/org/apache/SNX/util/OUtil.java

+5-42
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import java.io.InputStream;
55
import java.lang.management.ManagementFactory;
66
import java.lang.ref.WeakReference;
7-
import java.net.DatagramSocket;
8-
import java.net.InetAddress;
9-
import java.nio.charset.StandardCharsets;
107
import java.util.Map;
118
import java.util.Properties;
129

@@ -15,27 +12,6 @@ public class OUtil {
1512
public static final String DIR = System.getProperty("user.dir");
1613
public static Runtime RT = Runtime.getRuntime();
1714

18-
public static String trimStr(String s, int width) {
19-
if (s.length() > width)
20-
return s.substring(0, width - 1) + ".";
21-
else
22-
return s;
23-
}
24-
25-
public static byte[] toBa8(String str) {
26-
return str.getBytes(StandardCharsets.UTF_8);
27-
}
28-
29-
/**
30-
* Convert to String UT8
31-
*
32-
* @param ba
33-
* @return
34-
*/
35-
public static String toStr8(byte[] ba) {
36-
return new String(ba, StandardCharsets.UTF_8);
37-
}
38-
3915
public static Map loadProps(String fn) throws Throwable {
4016
InputStream input = new FileInputStream(fn);
4117

@@ -45,24 +21,11 @@ public static Map loadProps(String fn) throws Throwable {
4521
return props;
4622
}
4723

48-
protected static String _localHost;
49-
50-
public static synchronized String getLocalHost() {
51-
if (_localHost != null)
52-
return _localHost;
53-
54-
String h = null;
55-
try {
56-
final DatagramSocket socket = new DatagramSocket();
57-
58-
socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
59-
h = socket.getLocalAddress().getHostAddress();
60-
socket.close();
61-
} catch (Throwable e) {
62-
System.out.println(e.getMessage());
63-
}
64-
_localHost = h;
65-
return _localHost;
24+
public static String trimStr(String s, int width) {
25+
if (s.length() > width)
26+
return s.substring(0, width - 1) + ".";
27+
else
28+
return s;
6629
}
6730

6831
public String getPID() {

Diff for: docs/2020.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ We used to use PHP, ASP, JSP for SSR, heck 1/3 of WWW is PHP.
186186
But here is what we use in NodeJS, something more moderm:
187187

188188

189-
![](expressjs.gif)
189+
![](expressjs.png)
190190

191191
And in Java/Scala we can do this:
192192

Diff for: docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ We used to use PHP, ASP, JSP for SSR, heck 1/3 of WWW is PHP.
186186
But here is what we use in NodeJS, something more moderm:
187187

188188

189-
![](expressjs.gif)
189+
![](expressjs.png)
190190

191191
And in Java/Scala we can do this:
192192

Diff for: docs/expresjs.png

95.1 KB
Loading

Diff for: docs/expressjs.gif

-239 KB
Binary file not shown.

Diff for: docs/todo.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ S3
77

88
BigData
99

10+
Snowflake compatible sharing
11+
12+
Wasabi, Digital Ocean
1013

1114
// todo: jsass typescript4j scalia resiliance4j dns load javadoc
1215
implementation group: 'com.google.truth', name: 'truth', version: '1.0'

0 commit comments

Comments
 (0)