commit 913f1b79149cfc2e83ec211406db279483f4d103 Author: RĂ©mi Heredero <63239207+Klagarge@users.noreply.github.com> Date: Mon Dec 5 13:31:52 2022 +0100 Initial commit diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e43449a --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4a0d1ba --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..105ebb1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1639404417409 + + + + + + + + + \ No newline at end of file diff --git a/doc/allclasses-frame.html b/doc/allclasses-frame.html new file mode 100644 index 0000000..8b99cc2 --- /dev/null +++ b/doc/allclasses-frame.html @@ -0,0 +1,19 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/doc/allclasses-noframe.html b/doc/allclasses-noframe.html new file mode 100644 index 0000000..b142cc3 --- /dev/null +++ b/doc/allclasses-noframe.html @@ -0,0 +1,19 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/doc/ch/hevs/synd/sin/utils/Utility.html b/doc/ch/hevs/synd/sin/utils/Utility.html new file mode 100644 index 0000000..5c795a8 --- /dev/null +++ b/doc/ch/hevs/synd/sin/utils/Utility.html @@ -0,0 +1,800 @@ + + + + + +Utility + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
ch.hevs.synd.sin.utils
+

Class Utility

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/ch/hevs/synd/sin/utils/package-frame.html b/doc/ch/hevs/synd/sin/utils/package-frame.html new file mode 100644 index 0000000..eff46ae --- /dev/null +++ b/doc/ch/hevs/synd/sin/utils/package-frame.html @@ -0,0 +1,20 @@ + + + + + +ch.hevs.synd.sin.utils + + + + + +

ch.hevs.synd.sin.utils

+
+

Classes

+ +
+ + diff --git a/doc/ch/hevs/synd/sin/utils/package-summary.html b/doc/ch/hevs/synd/sin/utils/package-summary.html new file mode 100644 index 0000000..b009bfe --- /dev/null +++ b/doc/ch/hevs/synd/sin/utils/package-summary.html @@ -0,0 +1,140 @@ + + + + + +ch.hevs.synd.sin.utils + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Package ch.hevs.synd.sin.utils

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/ch/hevs/synd/sin/utils/package-tree.html b/doc/ch/hevs/synd/sin/utils/package-tree.html new file mode 100644 index 0000000..ac09e16 --- /dev/null +++ b/doc/ch/hevs/synd/sin/utils/package-tree.html @@ -0,0 +1,129 @@ + + + + + +ch.hevs.synd.sin.utils Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For Package ch.hevs.synd.sin.utils

+
+
+

Class Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/constant-values.html b/doc/constant-values.html new file mode 100644 index 0000000..ff0df8e --- /dev/null +++ b/doc/constant-values.html @@ -0,0 +1,149 @@ + + + + + +Constant Field Values + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Constant Field Values

+

Contents

+ +
+
+ + +

ch.hevs.*

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/deprecated-list.html b/doc/deprecated-list.html new file mode 100644 index 0000000..1780d5c --- /dev/null +++ b/doc/deprecated-list.html @@ -0,0 +1,120 @@ + + + + + +Deprecated List + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Deprecated API

+

Contents

+
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/help-doc.html b/doc/help-doc.html new file mode 100644 index 0000000..0cb8780 --- /dev/null +++ b/doc/help-doc.html @@ -0,0 +1,217 @@ + + + + + +API Help + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+ +This help file applies to API documentation generated using the standard doclet.
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-1.html b/doc/index-files/index-1.html new file mode 100644 index 0000000..56ad476 --- /dev/null +++ b/doc/index-files/index-1.html @@ -0,0 +1,127 @@ + + + + + +B-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

B

+
+
bytesToFloat(byte[], int, int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Returns a float value from array of bytes.
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-10.html b/doc/index-files/index-10.html new file mode 100644 index 0000000..6627962 --- /dev/null +++ b/doc/index-files/index-10.html @@ -0,0 +1,132 @@ + + + + + +W-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

W

+
+
waitSomeTime(int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
To wait some times ...
+
+
writeLine(OutputStream, byte[]) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Send the data contained in the given array of bytes through the output + stream.
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-2.html b/doc/index-files/index-2.html new file mode 100644 index 0000000..1d5a1ef --- /dev/null +++ b/doc/index-files/index-2.html @@ -0,0 +1,133 @@ + + + + + +C-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

C

+
+
calculateCRC(byte[], int, int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Calculates and returns the CRC using the data passed in parameters.
+
+
ch.hevs.synd.sin.utils - package ch.hevs.synd.sin.utils
+
 
+
checkCRC(byte[], int, int, byte[]) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Checks the CRC and returns true if it is correct, otherwise false.
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-3.html b/doc/index-files/index-3.html new file mode 100644 index 0000000..d5b8f95 --- /dev/null +++ b/doc/index-files/index-3.html @@ -0,0 +1,129 @@ + + + + + +D-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

D

+
+
DEBUG(String, String, String) - Static method in class ch.hevs.synd.sin.utils.Utility
+
 
+
DEBUG(Object, String, String) - Static method in class ch.hevs.synd.sin.utils.Utility
+
 
+
DEBUG(String, String, String, String) - Static method in class ch.hevs.synd.sin.utils.Utility
+
 
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-4.html b/doc/index-files/index-4.html new file mode 100644 index 0000000..6232d85 --- /dev/null +++ b/doc/index-files/index-4.html @@ -0,0 +1,127 @@ + + + + + +F-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

F

+
+
fileParser(String, String) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Method to use to access a file in your resources folder...
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-5.html b/doc/index-files/index-5.html new file mode 100644 index 0000000..8e1a9b9 --- /dev/null +++ b/doc/index-files/index-5.html @@ -0,0 +1,140 @@ + + + + + +G-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

G

+
+
getHexString(byte[]) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+
+
getHexString(byte[], int, int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+
+
getHexStringForDebug(byte[], int, int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f) and + format the string with `0xCC` where CC is the string in HEX
+
+
getStringRndVal(int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Retrieves a random value rounded to 2 decimal...
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-6.html b/doc/index-files/index-6.html new file mode 100644 index 0000000..d14a63f --- /dev/null +++ b/doc/index-files/index-6.html @@ -0,0 +1,127 @@ + + + + + +M-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

M

+
+
md5sum(String) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Returns the md5 of any input...
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-7.html b/doc/index-files/index-7.html new file mode 100644 index 0000000..4006f96 --- /dev/null +++ b/doc/index-files/index-7.html @@ -0,0 +1,141 @@ + + + + + +R-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

R

+
+
readBytes(InputStream) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Reads the incoming data from an input stream as long as there is + something to read and saved the data in an array of bytes.
+
+
readLine(InputStream) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Reads a line of text.
+
+
readNBytes(InputStream, int) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Reads from the given input stream an amount of bytes and retrieves these data as + an array of bytes.
+
+
rnd - Static variable in class ch.hevs.synd.sin.utils.Utility
+
+
Object to get some random values...
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-8.html b/doc/index-files/index-8.html new file mode 100644 index 0000000..21479c4 --- /dev/null +++ b/doc/index-files/index-8.html @@ -0,0 +1,131 @@ + + + + + +T-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

T

+
+
TCP_BUFFER_SIZE - Static variable in class ch.hevs.synd.sin.utils.Utility
+
+
Default size for the TCP input stream
+
+
threadWait(Thread, long) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
To be used to make a thread waiting for a certain amount of time
+
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index-files/index-9.html b/doc/index-files/index-9.html new file mode 100644 index 0000000..6729ef4 --- /dev/null +++ b/doc/index-files/index-9.html @@ -0,0 +1,133 @@ + + + + + +U-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
B C D F G M R T U W  + + +

U

+
+
unsignedByteToSignedInt(byte) - Static method in class ch.hevs.synd.sin.utils.Utility
+
+
Converts an unsigned byte to a signed integer.
+
+
Utility - Class in ch.hevs.synd.sin.utils
+
+
This class contains some useful Java methods to manipulate data.
+
+
Utility() - Constructor for class ch.hevs.synd.sin.utils.Utility
+
 
+
+B C D F G M R T U W 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/index.html b/doc/index.html new file mode 100644 index 0000000..3666e58 --- /dev/null +++ b/doc/index.html @@ -0,0 +1,72 @@ + + + + + +Generated Documentation (Untitled) + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="ch/hevs/synd/sin/utils/package-summary.html">Non-frame version</a>.</p> + + + diff --git a/doc/overview-tree.html b/doc/overview-tree.html new file mode 100644 index 0000000..2dfd8ab --- /dev/null +++ b/doc/overview-tree.html @@ -0,0 +1,133 @@ + + + + + +Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/doc/package-list b/doc/package-list new file mode 100644 index 0000000..27b34e7 --- /dev/null +++ b/doc/package-list @@ -0,0 +1 @@ +ch.hevs.synd.sin.utils diff --git a/doc/script.js b/doc/script.js new file mode 100644 index 0000000..b346356 --- /dev/null +++ b/doc/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/doc/stylesheet.css b/doc/stylesheet.css new file mode 100644 index 0000000..98055b2 --- /dev/null +++ b/doc/stylesheet.css @@ -0,0 +1,574 @@ +/* Javadoc style sheet */ +/* +Overall document style +*/ + +@import url('resources/fonts/dejavu.css'); + +body { + background-color:#ffffff; + color:#353833; + font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; + font-size:14px; + margin:0; +} +a:link, a:visited { + text-decoration:none; + color:#4A6782; +} +a:hover, a:focus { + text-decoration:none; + color:#bb7a2a; +} +a:active { + text-decoration:none; + color:#4A6782; +} +a[name] { + color:#353833; +} +a[name]:hover { + text-decoration:none; + color:#353833; +} +pre { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; +} +h1 { + font-size:20px; +} +h2 { + font-size:18px; +} +h3 { + font-size:16px; + font-style:italic; +} +h4 { + font-size:13px; +} +h5 { + font-size:12px; +} +h6 { + font-size:11px; +} +ul { + list-style-type:disc; +} +code, tt { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; + margin-top:8px; + line-height:1.4em; +} +dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; +} +table tr td dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + vertical-align:top; + padding-top:4px; +} +sup { + font-size:8px; +} +/* +Document title and Copyright styles +*/ +.clear { + clear:both; + height:0px; + overflow:hidden; +} +.aboutLanguage { + float:right; + padding:0px 21px; + font-size:11px; + z-index:200; + margin-top:-9px; +} +.legalCopy { + margin-left:.5em; +} +.bar a, .bar a:link, .bar a:visited, .bar a:active { + color:#FFFFFF; + text-decoration:none; +} +.bar a:hover, .bar a:focus { + color:#bb7a2a; +} +.tab { + background-color:#0066FF; + color:#ffffff; + padding:8px; + width:5em; + font-weight:bold; +} +/* +Navigation bar styles +*/ +.bar { + background-color:#4D7A97; + color:#FFFFFF; + padding:.8em .5em .4em .8em; + height:auto;/*height:1.8em;*/ + font-size:11px; + margin:0; +} +.topNav { + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.bottomNav { + margin-top:10px; + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.subNav { + background-color:#dee3e9; + float:left; + width:100%; + overflow:hidden; + font-size:12px; +} +.subNav div { + clear:left; + float:left; + padding:0 0 5px 6px; + text-transform:uppercase; +} +ul.navList, ul.subNavList { + float:left; + margin:0 25px 0 0; + padding:0; +} +ul.navList li{ + list-style:none; + float:left; + padding: 5px 6px; + text-transform:uppercase; +} +ul.subNavList li{ + list-style:none; + float:left; +} +.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { + color:#FFFFFF; + text-decoration:none; + text-transform:uppercase; +} +.topNav a:hover, .bottomNav a:hover { + text-decoration:none; + color:#bb7a2a; + text-transform:uppercase; +} +.navBarCell1Rev { + background-color:#F8981D; + color:#253441; + margin: auto 5px; +} +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; +} +/* +Page header and footer styles +*/ +.header, .footer { + clear:both; + margin:0 20px; + padding:5px 0 0 0; +} +.indexHeader { + margin:10px; + position:relative; +} +.indexHeader span{ + margin-right:15px; +} +.indexHeader h1 { + font-size:13px; +} +.title { + color:#2c4557; + margin:10px 0; +} +.subTitle { + margin:5px 0 0 0; +} +.header ul { + margin:0 0 15px 0; + padding:0; +} +.footer ul { + margin:20px 0 5px 0; +} +.header ul li, .footer ul li { + list-style:none; + font-size:13px; +} +/* +Heading styles +*/ +div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList ul.blockList li.blockList h3 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList li.blockList h3 { + padding:0; + margin:15px 0; +} +ul.blockList li.blockList h2 { + padding:0px 0 20px 0; +} +/* +Page layout container styles +*/ +.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { + clear:both; + padding:10px 20px; + position:relative; +} +.indexContainer { + margin:10px; + position:relative; + font-size:12px; +} +.indexContainer h2 { + font-size:13px; + padding:0 0 3px 0; +} +.indexContainer ul { + margin:0; + padding:0; +} +.indexContainer ul li { + list-style:none; + padding-top:2px; +} +.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { + font-size:12px; + font-weight:bold; + margin:10px 0 0 0; + color:#4E4E4E; +} +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:5px 0 10px 0px; + font-size:14px; + font-family:'DejaVu Sans Mono',monospace; +} +.serializedFormContainer dl.nameValue dt { + margin-left:1px; + font-size:1.1em; + display:inline; + font-weight:bold; +} +.serializedFormContainer dl.nameValue dd { + margin:0 0 0 1px; + font-size:1.1em; + display:inline; +} +/* +List styles +*/ +ul.horizontal li { + display:inline; + font-size:0.9em; +} +ul.inheritance { + margin:0; + padding:0; +} +ul.inheritance li { + display:inline; + list-style:none; +} +ul.inheritance li ul.inheritance { + margin-left:15px; + padding-left:15px; + padding-top:1px; +} +ul.blockList, ul.blockListLast { + margin:10px 0 10px 0; + padding:0; +} +ul.blockList li.blockList, ul.blockListLast li.blockList { + list-style:none; + margin-bottom:15px; + line-height:1.4; +} +ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { + padding:0px 20px 5px 10px; + border:1px solid #ededed; + background-color:#f8f8f8; +} +ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { + padding:0 0 5px 8px; + background-color:#ffffff; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { + margin-left:0; + padding-left:0; + padding-bottom:15px; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { + list-style:none; + border-bottom:none; + padding-bottom:0; +} +table tr td dl, table tr td dl dt, table tr td dl dd { + margin-top:0; + margin-bottom:1px; +} +/* +Table styles +*/ +.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { + width:100%; + border-left:1px solid #EEE; + border-right:1px solid #EEE; + border-bottom:1px solid #EEE; +} +.overviewSummary, .memberSummary { + padding:0px; +} +.overviewSummary caption, .memberSummary caption, .typeSummary caption, +.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { + position:relative; + text-align:left; + background-repeat:no-repeat; + color:#253441; + font-weight:bold; + clear:none; + overflow:hidden; + padding:0px; + padding-top:10px; + padding-left:1px; + margin:0px; + white-space:pre; +} +.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, +.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, +.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, +.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, +.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, +.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, +.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, +.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { + color:#FFFFFF; +} +.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, +.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + padding-bottom:7px; + display:inline-block; + float:left; + background-color:#F8981D; + border: none; + height:16px; +} +.memberSummary caption span.activeTableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#F8981D; + height:16px; +} +.memberSummary caption span.tableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#4D7A97; + height:16px; +} +.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { + padding-top:0px; + padding-left:0px; + padding-right:0px; + background-image:none; + float:none; + display:inline; +} +.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, +.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { + display:none; + width:5px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .activeTableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .tableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + background-color:#4D7A97; + float:left; + +} +.overviewSummary td, .memberSummary td, .typeSummary td, +.useSummary td, .constantsSummary td, .deprecatedSummary td { + text-align:left; + padding:0px 0px 12px 10px; +} +th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, +td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ + vertical-align:top; + padding-right:0px; + padding-top:8px; + padding-bottom:3px; +} +th.colFirst, th.colLast, th.colOne, .constantsSummary th { + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} +td.colFirst, th.colFirst { + white-space:nowrap; + font-size:13px; +} +td.colLast, th.colLast { + font-size:13px; +} +td.colOne, th.colOne { + font-size:13px; +} +.overviewSummary td.colFirst, .overviewSummary th.colFirst, +.useSummary td.colFirst, .useSummary th.colFirst, +.overviewSummary td.colOne, .overviewSummary th.colOne, +.memberSummary td.colFirst, .memberSummary th.colFirst, +.memberSummary td.colOne, .memberSummary th.colOne, +.typeSummary td.colFirst{ + width:25%; + vertical-align:top; +} +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; +} +.tableSubHeadingColor { + background-color:#EEEEFF; +} +.altColor { + background-color:#FFFFFF; +} +.rowColor { + background-color:#EEEEEF; +} +/* +Content styles +*/ +.description pre { + margin-top:0; +} +.deprecatedContent { + margin:0; + padding:10px 0; +} +.docSummary { + padding:0; +} + +ul.blockList ul.blockList ul.blockList li.blockList h3 { + font-style:normal; +} + +div.block { + font-size:14px; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; +} + +td.colLast div { + padding-top:0px; +} + + +td.colLast a { + padding-bottom:3px; +} +/* +Formatting effect styles +*/ +.sourceLineNo { + color:green; + padding:0 30px 0 0; +} +h1.hidden { + visibility:hidden; + overflow:hidden; + font-size:10px; +} +.block { + display:block; + margin:3px 10px 2px 0px; + color:#474747; +} +.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, +.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, +.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { + font-weight:bold; +} +.deprecationComment, .emphasizedPhrase, .interfaceName { + font-style:italic; +} + +div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, +div.block div.block span.interfaceName { + font-style:normal; +} + +div.contentContainer ul.blockList li.blockList h2{ + padding-bottom:0px; +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b468cc1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + ch.hevs.synd.sin + UIServerStudents + 1.0 + + + 8 + 8 + + + + + + com.fasterxml.jackson.core + jackson-core + 2.13.0 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.13.0 + + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + \ No newline at end of file diff --git a/src/main/java/ch/hevs/synd/sin/UICommands.java b/src/main/java/ch/hevs/synd/sin/UICommands.java new file mode 100644 index 0000000..436b8d8 --- /dev/null +++ b/src/main/java/ch/hevs/synd/sin/UICommands.java @@ -0,0 +1,19 @@ +package ch.hevs.synd.sin; + +/** + * @author Patrice Rudaz + * @date December 2021 + * @version 1.0.0 + */ +public class UICommands { + + public static final String STOP_COMMAND = "Stop"; + + public static final String GET_U_COMMAND = "Get U"; + public static final String GET_U_SHORT_COMMAND = "GetU"; + + public static final String GET_I_COMMAND = "Get I"; + public static final String GET_I_SHORT_COMMAND = "GetI"; + + public static final String INVALID_COMMND = "Invalid Command!"; +} diff --git a/src/main/java/ch/hevs/synd/sin/UIConstants.java b/src/main/java/ch/hevs/synd/sin/UIConstants.java new file mode 100644 index 0000000..2764b6c --- /dev/null +++ b/src/main/java/ch/hevs/synd/sin/UIConstants.java @@ -0,0 +1,17 @@ +package ch.hevs.synd.sin; + +/** + * @author Patrice Rudaz + * @date December 2021 + * @version 1.0.0 + */ +public class UIConstants { + /** Defining the default port number to be used. */ + public static final int UI_SERVER_PORT = 1502; + public static final int UI_BUFFER_MAX_SIZE = 256; + + /** Messages for DatagramSocket examples */ + public static final String OK_MESSAGE = "200 OK"; + public static final String KO_MESSAGE = "401 Bad formatted request"; + +} diff --git a/src/main/java/ch/hevs/synd/sin/network/server/Transaction.java b/src/main/java/ch/hevs/synd/sin/network/server/Transaction.java new file mode 100644 index 0000000..ce1406a --- /dev/null +++ b/src/main/java/ch/hevs/synd/sin/network/server/Transaction.java @@ -0,0 +1,69 @@ +package ch.hevs.synd.sin.network.server; + +import ch.hevs.synd.sin.sensor.Sensor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class Transaction { + + private final InputStream _in; + private final OutputStream _out; + + private final Sensor _uSensor; + private final Sensor _iSensor; + + + /* **************************************************************************************************************** */ + /* */ + /* Constructors */ + /* */ + /* **************************************************************************************************************** */ + /** + * Simple constructor + * @param in The input stream to read from + * @param out The output stream to write to + * @param uSensor Pointer to the Voltage sensor + * @param iSensor Pointer to the Ampere sensor + */ + public Transaction(InputStream in, OutputStream out, Sensor uSensor, Sensor iSensor) { + _in = in; + _out = out; + _uSensor = uSensor; + _iSensor = iSensor; + } + + + /* **************************************************************************************************************** */ + /* */ + /* Public methods */ + /* */ + /* **************************************************************************************************************** */ + public boolean processTransaction() { + // TODO: Put your code here... + return false; + } + + + /* **************************************************************************************************************** */ + /* */ + /* Private methods */ + /* */ + /* **************************************************************************************************************** */ + // Private method which will interpret the given command and react in to it... + private boolean transaction(String dataIn) throws IOException { + // TODO: Analyze here the given action (dataIn) and react in to it by sending the correct reply to the output stream + return false; + } + + + /* **************************************************************************************************************** */ + /* */ + /* MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- MAIN -- */ + /* */ + /* **************************************************************************************************************** */ + public static void main(String[] args) { + // TODO: Put your code here + } +} diff --git a/src/main/java/ch/hevs/synd/sin/sensor/Measurement.java b/src/main/java/ch/hevs/synd/sin/sensor/Measurement.java new file mode 100644 index 0000000..8f2c498 --- /dev/null +++ b/src/main/java/ch/hevs/synd/sin/sensor/Measurement.java @@ -0,0 +1,76 @@ +package ch.hevs.synd.sin.sensor; + +import java.util.Date; + +public class Measurement { + public static final int TIMESTAMP_ROUND_FACTOR = 25; + public static final double VOLTAGE_VALUE_FACTOR = 230; + public static final double CURRENT_VALUE_FACTOR = 15; + + private final MeasurementType _type; + private final double _factor; + private int _phase; + private final int _phaseShift; + private double _value; + private long _unixTimeStamp; + + + /* ************************************************************************************************************ */ + /* */ + /* Constructors */ + /* */ + /* ************************************************************************************************************ */ + public Measurement(MeasurementType type, int phaseShift) { + _type = type; + + if (_type.equals(MeasurementType.Voltage)) { + _factor = VOLTAGE_VALUE_FACTOR; + } else { + _factor = CURRENT_VALUE_FACTOR; + } + _phaseShift = phaseShift; + _value = _getValue(0); + _unixTimeStamp = _getTimestamp(); + } + + + /* ************************************************************************************************************ */ + /* Getter */ + /* ************************************************************************************************************ */ + public MeasurementType getType() { + return _type; + } + + public long getUnixTimeStamp() { + return _unixTimeStamp; + } + + public double getValue() { + return _value; + } + + public int getPhase() { + return _phase; + } + + /* ************************************************************************************************************ */ + /* Public Section */ + /* ************************************************************************************************************ */ + public void setPhase(int phase) { + _value = _getValue(phase); + _unixTimeStamp = _getTimestamp(); + } + + /* ************************************************************************************************************ */ + /* Private methods */ + /* ************************************************************************************************************ */ + private long _getTimestamp() { + return (new Date()).getTime() * TIMESTAMP_ROUND_FACTOR / TIMESTAMP_ROUND_FACTOR; + } + + private double _getValue(int phase) { + _phase = phase % 360; + return Math.sin(Math.toRadians(phase + _phaseShift)) * _factor; + } + +} diff --git a/src/main/java/ch/hevs/synd/sin/sensor/MeasurementType.java b/src/main/java/ch/hevs/synd/sin/sensor/MeasurementType.java new file mode 100644 index 0000000..ae8e3e5 --- /dev/null +++ b/src/main/java/ch/hevs/synd/sin/sensor/MeasurementType.java @@ -0,0 +1,23 @@ +package ch.hevs.synd.sin.sensor; + +/** + * Definition of all available types of measurement + * + * @author Patrice Rudaz + * @date December 2021 + * @version 1.0.0 + */ +public enum MeasurementType { + Voltage, + Current; + + public String toString() { + + if (equals(Voltage)) + return " [V]"; + else if (equals(Current)) + return " [A]"; + else + return "Unknown Type"; + } +} diff --git a/src/main/java/ch/hevs/synd/sin/sensor/Sensor.java b/src/main/java/ch/hevs/synd/sin/sensor/Sensor.java new file mode 100644 index 0000000..5a1837d --- /dev/null +++ b/src/main/java/ch/hevs/synd/sin/sensor/Sensor.java @@ -0,0 +1,58 @@ +package ch.hevs.synd.sin.sensor; + +import java.util.Timer; +import java.util.TimerTask; + +public class Sensor { + private final Measurement _measurement; + private Timer _tMeasurement; + + /* ************************************************************************************************************ */ + /* */ + /* Constructors */ + /* */ + /* ************************************************************************************************************ */ + public Sensor(MeasurementType type, int phaseShift) { + // Set up measurement of the sensor + _measurement = new Measurement(type, phaseShift); + + // Set up a timer task + _tMeasurement = new Timer(); + SensorTask sensorTask = new SensorTask(_measurement); + _tMeasurement.scheduleAtFixedRate(sensorTask, 0, Measurement.TIMESTAMP_ROUND_FACTOR); + } + + + /* ************************************************************************************************************ */ + /* Getter */ + /* ************************************************************************************************************ */ + public Measurement getMeasurement() { + return _measurement; + } + + + /* ************************************************************************************************************ */ + /* Public Section */ + /* ************************************************************************************************************ */ + public void shutdown() { + if (_tMeasurement != null) { + _tMeasurement.cancel(); + _tMeasurement.purge(); + } + } + + /* ************************************************************************************************************ */ + /* Private Section */ + /* ************************************************************************************************************ */ + private class SensorTask extends TimerTask { + private Measurement _measurement; + + SensorTask(Measurement measurement) { + _measurement = measurement; + } + + public void run() { + _measurement.setPhase(_measurement.getPhase() + 3); + } + } +} diff --git a/src/main/java/ch/hevs/utils/Utility.java b/src/main/java/ch/hevs/utils/Utility.java new file mode 100644 index 0000000..7e29fee --- /dev/null +++ b/src/main/java/ch/hevs/utils/Utility.java @@ -0,0 +1,411 @@ +package ch.hevs.utils; + +import java.io.*; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Random; + +/** + * This class contains some useful Java methods to manipulate data. + * + * @author Michael Clausen + * @author Patrice Rudaz + */ +@SuppressWarnings("unused") +public class Utility { + /** Default size for the TCP input stream */ + public static final int TCP_BUFFER_SIZE = 4096; + + /** Object to get some random values... */ + public static Random rnd = new Random(1); + + /** + * Calculates and returns the CRC using the data passed in parameters. + * + * @param data a byte array containing the data to send + * @param offset the offset + * @param len the data length + * @return byte[] the CRC + */ + public static byte[] calculateCRC(byte[] data , int offset , int len) + { + int crc = 0x0000FFFF; + for (int i = 0 ; i < len ; i++) { + crc = crc ^ Utility.unsignedByteToSignedInt(data[i + offset]); + for (int j = 0 ; j < 8 ; j++) { + int tmp = crc; + int carryFlag = tmp & 0x0001; + crc = crc >> 1; + if (carryFlag == 1) { + crc = crc ^ 0xA001; + } + } + } + + byte[] result = new byte[2]; + result[0] = (byte)(crc & 0xFF); + result[1] = (byte)((crc & 0xFF00) >> 8); + + return result; + } + + /** + * Checks the CRC and returns true if it is correct, otherwise false. + * + * @param data a byte array containing the data to send + * @param offset the offset + * @param len the data length + * @param crc a byte array containing the CRC to check + * @return boolean true if the CRC is correct, otherwise false + */ + public static boolean checkCRC(byte[] data , int offset , int len , byte[] crc) + { + byte[] calcCrc = Utility.calculateCRC(data , offset , len); + return (calcCrc[0] == crc[0] && calcCrc[1] == crc[1]); + } + + + /** + * Returns a float value from array of bytes. This byte's array can only be 2 or 4 bytes long. + * @param bytes The array of bytes to convert. + * @param offset The position where the method has to start to get the bytes from. + * @param size The amount of bytes to convert. + * @return A Float value or null if the process failed. + */ + public static Float bytesToFloat(byte[] bytes, int offset, int size) { + + if (size == 2 || size == 4) { + byte[] tmp = new byte[4]; + System.arraycopy(bytes, offset, tmp, 0, size); + try { + return ByteBuffer.wrap(tmp).order(ByteOrder.BIG_ENDIAN).getFloat(); + } catch (Exception e) { + DEBUG("utils", "Utility", "bytesToFloat()", "ByteBufferException : " + e.getMessage()); + } + } else { + DEBUG("utils", "Utility", "bytesToFloat()", "ERROR: size MUST be 2 or 4 !!!"); + } + return null; + } + + /** + * Converts an unsigned byte to a signed integer. + * @param from an unsigned byte to convert to a signed integer + * @return int a signed integer + */ + public static int unsignedByteToSignedInt(byte from) + { + return 0x000000FF & (int)from; + } + + /** + * Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f) + * @param b The array of bytes to be convert in HEX characters. + * @return A string representing the given array of byte in HEX values. + */ + public static String getHexString(byte[] b) { + return getHexString(b, 0, b.length); + } + + /** + * Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f) + * @param b The byte array to convert in HEX string + * @param offset The index where we start to convert from. + * @param length The amount of bytes to convert in HEX string + * @return A String representing the HEX values of the selected bytes of the array. + */ + public static String getHexString(byte[] b, int offset, int length) { + StringBuilder result = new StringBuilder(); + for (int i = offset; i < offset+length; i++) { + result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1)); + } + return result.toString(); + } + + /** + * Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f) and + * format the string with `0xCC` where CC is the string in HEX + * @param b The byte array to convert in HEX string + * @param offset The index where we start to convert from. + * @param length The amount of bytes to convert in HEX string + * @return A String representing the HEX values of the selected bytes of the array. + */ + public static String getHexStringForDebug(byte[] b, int offset, int length) { + StringBuilder result = new StringBuilder(); + for (int i = offset; i < offset+length; i++) { + result.append("0x"); + result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1)); + result.append(" "); + } + return result.toString().trim(); + } + + + /** + * To be used to make a thread waiting for a certain amount of time + * @param thread The thread to be stopped + * @param millis The amount of time in [ms] to stop the thread. + */ + public static void threadWait(Thread thread, long millis) { + try { + thread.wait(millis); + } catch(InterruptedException ie) { + DEBUG("utils", "Utility", "threadWait()", "InterruptedException : " + ie.getMessage()); + } catch (NullPointerException npe) { + DEBUG("utils", "Utility", "threadWait()", "The given Thread is NULL !"); + } + } + + /** + * To wait some times ... + * + * @param ms The milliseconds to wait... + */ + public static void waitSomeTime(int ms) + { + try { + Thread.sleep(ms); + } catch(InterruptedException e) { + DEBUG("utils", "Utility", "waitSomeTime()", "InterruptedException : " + e.getMessage()); + } + } + + + /** + * Returns the md5 of any input... + * @param msg The input string to process + * @return The md5 of the input string. + */ + public static String md5sum(String msg) + { + try { + MessageDigest md = MessageDigest.getInstance("md5"); + return String.format("%032x", new BigInteger(1, md.digest(msg.getBytes(StandardCharsets.UTF_8)))); + } catch (NoSuchAlgorithmException e) { + DEBUG("utils", "Utility", "md5sum()", "NoSuchAlgorithmException : " + e.getMessage()); + } + return null; + } + + /** + * Retrieves a random value rounded to 2 decimal... + * + * @param factor A coefficient which the random value is multiplied with. + * @return A random value rounded to 2 decimal converted to a String. + */ + public static String getStringRndVal(int factor) { + float val = (float) rnd.nextDouble()*factor*10; + return String.format("%.2f", val).replace(",", "."); + } + + + /** + * Reads the incoming data from an input stream as long as there is + * something to read and saved the data in an array of bytes. + * + * The method is blocking ! + * This method blocks until input data is available, end of file is detected, + * or an exception is thrown. + * + * If the length of of read data is zero, then no bytes are read and an empty + * array of bytes is returned; otherwise, there is an attempt to read at least + * one byte. If no byte is available because the stream is at the end of the + * file, the value -1 is returned; otherwise, at least one byte is read and + * returned as an array of bytes. + * + * @param in The input Stream where to read the data coming from. + * @return The read data as an array of bytes. Or null if the + * has been closed by the peer while waiting for incoming data. + * @throws IOException If the first byte cannot be read for any reason other + * than the end of the file, if the input stream has been + * closed, or if some other I/O error occurs. + */ + public static byte[] readBytes(InputStream in) throws IOException + { + byte[] buffer = new byte[TCP_BUFFER_SIZE]; + + // Read the incoming data + int b = in.read(buffer); + + // Creates an array of bytes with the right size + if (b == -1) return null; // the connection has been canceled by the peer + if (b == 0) return new byte[0]; // empty data + else { // The received data + byte[] rBytes = new byte[b]; + System.arraycopy(buffer, 0, rBytes, 0, b); + return rBytes; + } + } + + /** + * Reads from the given input stream an amount of bytes and retrieves these data as + * an array of bytes. This method is + * + * The method is blocking ! + * + * @param in The input Stream where to read the data coming from. + * @param len The number of bytes to be read from the input stream. + * + * @return The read data as an array of bytes. + * + * @throws IOException If the first byte cannot be read for any reason other + * than the end of the file, if the input stream has been + * closed, or if some other I/O error occurs. + */ + public static byte[] readNBytes(InputStream in, int len) throws IOException + { + byte[] buffer = new byte[len]; + + // Checks that there is enough available data to read from the input stream + int counter = 0; + while (in.available() < len) { + Utility.waitSomeTime(2); + if (++counter > 10) + return null; + } + + // Read the incoming data + int b = in.read(buffer, 0, len); + + // Creates an array of bytes with the right size + if (b == -1) return null; // the connection has been canceled by the peer + else if (b == 0) return new byte[0]; // empty data + else return buffer; // The received data + } + + /** + * Reads a line of text. A line is considered to be terminated by any one of a + * line feed ('\n'), a carriage return ('\r'), or a carriage return followed + * immediately by a line feed. + * + * @param in The Input Stream to read from. + * @return An array of bytes containing the contents of the line, not including any + * line-termination characters, or null if the end of the stream has + * been reached. + * @throws IOException If an I/O error occurs + */ + public static byte[] readLine(InputStream in) throws IOException + { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + + // Read a complete line with Cariage Return and/or Line Feed + String line = reader.readLine(); + + // Handle the value to return + if (line != null) + return line.replace("\n", "").replace("\r", "").getBytes(); + else + return null; + } + + /** + * Send the data contained in the given array of bytes through the output + * stream. It raises an IOException if something goes wrong. + * The method returns the amount of bytes sent. + * + * @param out The Output Stream to send the data to. + * @param toSend The data to send + * @throws IOException If an I/O error occurs + */ + public static void writeLine(OutputStream out, byte[] toSend) throws IOException { + + if (toSend[toSend.length - 1] == '\n') + out.write(toSend); + else { + byte[] temp = new byte[toSend.length + 2]; + System.arraycopy(toSend, 0, temp, 0, toSend.length); + temp[temp.length - 2] = (byte) '\r'; + temp[temp.length - 1] = (byte) '\n'; + out.write(temp); + } + + out.flush(); + } + + + /** + * Method to use to access a file in your resources folder... + * @param pathName folder's name (if exists) from `resources` + * @param fileName Name of the file to access + * + * @return A BufferedReader related to the file you want to work with, or null if the file could not be reached. + */ + public static BufferedReader fileParser(String pathName, String fileName) { + // set relative path + InputStream is; + if (pathName == null) { + is = ClassLoader.getSystemClassLoader().getResourceAsStream(fileName); + } else { + is = ClassLoader.getSystemClassLoader().getResourceAsStream(pathName + "/" + fileName); + } + + if (is != null) { + return new BufferedReader(new InputStreamReader(is)); + } + return null; + } + + + // DEBUG System.out + public static void DEBUG(String className, String method, String msg) { + DEBUG(null, className, method, msg); + } + + public static void DEBUG(Object object, String method, String msg) { + String className = object.getClass().getSimpleName(); + String[] packages = object.getClass().getPackage().getName().split("\\."); + if (packages.length > 1) + DEBUG(packages[packages.length-1], className, method, msg); + else if (packages.length == 1) + DEBUG(packages[0], className, method, msg); + else + DEBUG(null, className, method, msg); + } + + public static void DEBUG(String packageName, String className, String method, String msg) { + final int nameLength = 25; + int millis = Calendar.getInstance().get(Calendar.MILLISECOND); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + + className = className.trim().replace("[", "").replace("]", ""); + if (packageName != null) + className = packageName + ":" + className; + + String cn = " [" + className + "] "; + while (cn.length() < nameLength) { + cn += " "; + } + StringBuilder logMsg = new StringBuilder(); + + // set the time + logMsg.append(sdf.format(Calendar.getInstance().getTime())).append(".").append(String.format("%03d", millis)); + + // Append Packages and ClassName + logMsg.append(cn); + + // Append Method + method = method.trim().replace("(", "").replace(")", ""); + method += "() > "; + while (method.length() < nameLength) { + method += " "; + } + logMsg.append(method); + + // Append message if exists + if (msg != null) { + logMsg.append(msg); + } + + if (logMsg.toString().endsWith("\n")) { + System.out.print(logMsg); + } else { + System.out.println(logMsg); + } + } +}