Skip to content

Commit f1028c7

Browse files
committed
Added getZeroTerminatedString method to DataRequest class.
Added variable, enumeration, get and set methods to StringRequest class. When using the getValue() function, the class now by default will convert the contents of the underlying byte buffer up to first zero byte. But thi can be changed by added methods. Updated release files and started some real versioning. This is now version 1.0.2.
1 parent e6c4427 commit f1028c7

File tree

200 files changed

+1318
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+1318
-551
lines changed

CHANGELOG.txt

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
27.8.2021
2+
3+
The oficial version number is now: 1.0.2
4+
5+
Added: The ValueRetrieveMethod enumeration to the StringRequest class, the variable and the respective get and set methods for this enumeration. It now drives how the underlying byte buffer will be converted to string. Either: TO_FIRST_ZERO_BYTE - will use the added getZeroTerminatedString function, or: WHOLE_BUFFER - which will return the content of the whole buffer. By default, the StringRequest class uses TO_FIRST_ZERO_BYTE. You can change this using the new setValueRetrieveMethod(ValueRetrieveMethod valueRetrieveMethod) function, or by using getValue(ValueRetrieveMethod valueRetrieveMethod), which will not change the stored behavior of the class.
6+
Added: The getZeroTerminatedString(Charset charset) function to DataRequest class that will return the contents of the underlying byte buffer up to first zero byte converted to String.
7+
Changed: Modified build.xml so for the Netbeans project, so it now generates jar files with version number.
8+
Updates: The respective archives and folders with ready to distributon (compiled) files.
9+
10+
111
3.1.2021
212

313
Added: Some Junit tests.

FSUIPC/build.xml

+8-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@
7070
nbproject/build-impl.xml file.
7171
7272
-->
73+
<target name="-pre-init">
74+
<property file="version.properties"/>
75+
<property name="dist.jar" value="dist/${ant.project.name}-${project.version}.jar"/>
76+
</target>
77+
7378
<target name="-post-jar" description="bundle sources and javadoc in a jar" depends="javadoc">
74-
<jar compress="${jar.compress}" basedir="${src.dir}" jarfile="${dist.dir}/${application.title}-sources.jar"/>
75-
<jar compress="${jar.compress}" basedir="${test.src.dir}" jarfile="${dist.dir}/${application.title}-test.jar"/>
76-
<jar compress="${jar.compress}" basedir="${dist.javadoc.dir}" jarfile="${dist.dir}/${application.title}-javadoc.jar"/>
79+
<jar compress="${jar.compress}" basedir="${src.dir}" jarfile="${dist.dir}/${application.title}-${project.version}-sources.jar"/>
80+
<jar compress="${jar.compress}" basedir="${test.src.dir}" jarfile="${dist.dir}/${application.title}-${project.version}-test.jar"/>
81+
<jar compress="${jar.compress}" basedir="${dist.javadoc.dir}" jarfile="${dist.dir}/${application.title}-${project.version}-javadoc.jar"/>
7782
</target>
7883
</project>

FSUIPC/build/built-jar.properties

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Fri, 27 Aug 2021 18:59:51 +0200
2+
3+
4+
P\:\\Java\\Murdock_FSUIPC\\FSUIPC=
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
compile.on.save=true
1+
compile.on.save=false
22
do.depend=false
33
do.jar=true
44
do.jlink=false
55
javac.debug=true
66
javadoc.preview=true
77
jlink.strip=false
8-
user.properties.file=C:\\Users\\Murdock\\AppData\\Roaming\\NetBeans\\12.2\\build.properties
8+
user.properties.file=C:\\Users\\Murdock\\AppData\\Roaming\\NetBeans\\12.4\\build.properties

FSUIPC/nbproject/private/private.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
33
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
44
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
5-
<group/>
5+
<group>
6+
<file>file:/P:/Java/Murdock_FSUIPC/FSUIPC/src/com/mouseviator/fsuipc/datarequest/primitives/StringRequest.java</file>
7+
</group>
68
</open-files>
79
</project-private>

FSUIPC/src/com/mouseviator/fsuipc/datarequest/DataRequest.java

+24
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,30 @@ protected void convertStringToByteArray(String value, int max_size, Charset char
371371
//put zero at the end
372372
dataBuffer[bufferLength - 1] = (byte) 0;
373373
}
374+
375+
/**
376+
* This function will convert byte array to string ending at first zero byte.
377+
*
378+
* @param charset Charset to use when encoding the string.
379+
* @return The contents of underlying byte up to first zero byte buffer converted to String.
380+
*/
381+
protected String getZeroTerminatedString(Charset charset) {
382+
int firstZeroBytePos = dataBuffer.length;
383+
for (int i = 0; i < dataBuffer.length; i++) {
384+
if (dataBuffer[i] == 0) {
385+
firstZeroBytePos = i;
386+
break;
387+
}
388+
}
389+
390+
//check if empty string...
391+
if (firstZeroBytePos == 0) {
392+
firstZeroBytePos = 1;
393+
}
394+
395+
String result = new String(dataBuffer, 0, firstZeroBytePos, charset);
396+
return result;
397+
}
374398

375399
/**
376400
* This helper function will copy the given byte array into the internal byte array. This will be copy of the

FSUIPC/src/com/mouseviator/fsuipc/datarequest/primitives/StringRequest.java

+88-49
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,28 @@
1818
import java.security.InvalidParameterException;
1919

2020
/**
21-
* This class implements string data request for use with
22-
* {@link com.mouseviator.fsuipc.FSUIPC} class. Well, FSUIPC will read/write
23-
* string values as series of bytes, usually terminated as classic C string, by
24-
* 0 byte. But with Strings we always have this problem with encoding... so to
25-
* keep the scalability, this data request allows you to set encoding that will
26-
* be used to convert the internal byte data buffer holding the string to the
27-
* actual Java string. You can set this encoding using various constructors or
28-
* by the {@link #setCharset(java.nio.charset.Charset) } method. The charset for
29-
* encoding/decoding the string will be initialized to the system default,
30-
* which, mostly, will be UTF-8.
21+
* This class implements string data request for use with {@link com.mouseviator.fsuipc.FSUIPC} class. Well, FSUIPC will
22+
* read/write string values as series of bytes, usually terminated as classic C string, by 0 byte. But with Strings we
23+
* always have this problem with encoding... so to keep the scalability, this data request allows you to set encoding
24+
* that will be used to convert the internal byte data buffer holding the string to the actual Java string. You can set
25+
* this encoding using various constructors or by the {@link #setCharset(java.nio.charset.Charset) } method. The charset
26+
* for encoding/decoding the string will be initialized to the system default, which, mostly, will be UTF-8.
3127
*
3228
*
3329
* @author Mouseviator
3430
*/
3531
public class StringRequest extends DataRequest implements IDataRequest<String> {
3632

3733
private Charset charset = Charset.defaultCharset();
34+
private ValueRetrieveMethod valueRetrieveMethod = ValueRetrieveMethod.WHOLE_BUFFER;
3835

3936
/**
40-
* Creates a new string data request associated with given offset and the
41-
* byte data buffer initialized to given size. Note that this is only useful
42-
* for READ type request. If you use the {@link #setValue(java.lang.String)
43-
* } method later on this object, the byte array created by this constructor
44-
* will be discarded.
37+
* Creates a new string data request associated with given offset and the byte data buffer initialized to given
38+
* size. Note that this is only useful for READ type request. If you use the {@link #setValue(java.lang.String)
39+
* } method later on this object, the byte array created by this constructor will be discarded.
4540
*
4641
* @param offset An offset to associate this data request with.
47-
* @param size The size of the byte data buffer to hold the string
48-
* characters.
42+
* @param size The size of the byte data buffer to hold the string characters.
4943
*/
5044
public StringRequest(int offset, int size) throws InvalidParameterException {
5145
if (offset >= MIN_OFFSET_VALUE && offset <= MAX_OFFSET_VALUE && size > 0) {
@@ -57,10 +51,9 @@ public StringRequest(int offset, int size) throws InvalidParameterException {
5751
}
5852

5953
/**
60-
* Creates a new string data request associated with given offset and
61-
* initialized to given string value. The conversion of the string to byte
62-
* data buffer will happen using the system default charset. The data
63-
* request type will be set to WRITE.
54+
* Creates a new string data request associated with given offset and initialized to given string value. The
55+
* conversion of the string to byte data buffer will happen using the system default charset. The data request type
56+
* will be set to WRITE.
6457
*
6558
* @param offset An offset to associate this data request with.
6659
* @param value A string to set for this data request value.
@@ -77,13 +70,10 @@ public StringRequest(int offset, String value) throws InvalidParameterException
7770
}
7871

7972
/**
80-
* Creates a new string data request associated with given offset and
81-
* initialized to given string value. If the byte data buffer, that will be
82-
* result of converting given string value to byte array, is longer than
83-
* max_size, it will be trimmed to the (max_size - 1) - the last byte will
84-
* be set to 0. The conversion of the string to byte data buffer will happen
85-
* using the system default charset. The data request type will be set to
86-
* WRITE.
73+
* Creates a new string data request associated with given offset and initialized to given string value. If the byte
74+
* data buffer, that will be result of converting given string value to byte array, is longer than max_size, it will
75+
* be trimmed to the (max_size - 1) - the last byte will be set to 0. The conversion of the string to byte data
76+
* buffer will happen using the system default charset. The data request type will be set to WRITE.
8777
*
8878
* @param offset An offset to associate this data request with.
8979
* @param max_size Maximum size of the resulting byte data buffer.
@@ -102,10 +92,9 @@ public StringRequest(int offset, int max_size, String value) throws InvalidParam
10292
}
10393

10494
/**
105-
* Creates a new string data request associated with given offset and
106-
* initialized to given string value.The conversion of the string to byte
107-
* data buffer will happen using the provided charset. The data request type
108-
* will be set to WRITE.
95+
* Creates a new string data request associated with given offset and initialized to given string value.The
96+
* conversion of the string to byte data buffer will happen using the provided charset. The data request type will
97+
* be set to WRITE.
10998
*
11099
* @param offset An offset to associate this data request with.
111100
* @param value A string to set for this data request value.
@@ -115,7 +104,7 @@ public StringRequest(int offset, String value, Charset charset) throws InvalidPa
115104
if (offset >= MIN_OFFSET_VALUE && offset <= MAX_OFFSET_VALUE) {
116105
//convert to internal byte array
117106
convertStringToByteArray(value, 0, charset);
118-
107+
119108
this.charset = charset;
120109
this.offset = offset;
121110
this.type = RequestType.WRITE;
@@ -125,12 +114,10 @@ public StringRequest(int offset, String value, Charset charset) throws InvalidPa
125114
}
126115

127116
/**
128-
* Creates a new string data request associated with given offset and
129-
* initialized to given string value.If the byte data buffer, that will be
130-
* result of converting given string value to byte array, is longer than
131-
* max_size, it will be trimmed to the (max_size - 1) - the last byte will
132-
* be set to 0. The conversion of the string to byte data buffer will happen
133-
* using the provided charset. The data request type will be set to WRITE.
117+
* Creates a new string data request associated with given offset and initialized to given string value.If the byte
118+
* data buffer, that will be result of converting given string value to byte array, is longer than max_size, it will
119+
* be trimmed to the (max_size - 1) - the last byte will be set to 0. The conversion of the string to byte data
120+
* buffer will happen using the provided charset. The data request type will be set to WRITE.
134121
*
135122
* @param offset An offset to associate this data request with.
136123
* @param max_size Maximum size of the resulting byte data buffer.
@@ -151,9 +138,8 @@ public StringRequest(int offset, int max_size, String value, Charset charset) th
151138
}
152139

153140
/**
154-
* This function will allocate the internat byte data buffer to specified
155-
* size, creating new buffer, thus, throwing away any data that this data
156-
* request held before.
141+
* This function will allocate the internat byte data buffer to specified size, creating new buffer, thus, throwing
142+
* away any data that this data request held before.
157143
*
158144
* @param size The required size of the byte data buffer.
159145
*/
@@ -164,19 +150,40 @@ public void allocate(int size) {
164150
}
165151

166152
@Override
153+
/**
154+
* This function will return underlying byte data buffer as String. How the value will be retrieved depends on what value is set
155+
* {@link #getValueRetrieveMethod()}.
156+
*
157+
* @return String representation of the underlying byte data buffer.
158+
*/
167159
public String getValue() {
168-
return new String(dataBuffer, charset).trim();
160+
return getValue(valueRetrieveMethod);
161+
}
162+
163+
/**
164+
* This function will return underlying byte data buffer as String. You have to specify how the value will be retrieved
165+
* by <code>valueRetrieveMethod</code> parameter.
166+
*
167+
* @param valueRetrieveMethod The method to retrieve the value.
168+
* @return String representation of the underlying byte data buffer.
169+
*/
170+
public String getValue(ValueRetrieveMethod valueRetrieveMethod) {
171+
if (valueRetrieveMethod == ValueRetrieveMethod.WHOLE_BUFFER) {
172+
return new String(dataBuffer, charset).trim();
173+
} else {
174+
return getZeroTerminatedString(charset);
175+
}
169176
}
170177

171178
@Override
172179
public void setValue(String value) {
173180
convertStringToByteArray(value, 0, charset);
174181
}
175-
182+
176183
/**
177-
* This function will set value of this StringRequest to given string, but the resulting length
178-
* of the byte array of the converted string will be max_size.
179-
*
184+
* This function will set value of this StringRequest to given string, but the resulting length of the byte array of
185+
* the converted string will be max_size.
186+
*
180187
* @param value A string value to set.
181188
* @param max_size The maximum length of the byte buffer of the converted string.
182189
*/
@@ -195,14 +202,46 @@ public void setCharset(Charset charset) {
195202
this.charset = charset;
196203
}
197204
}
198-
205+
199206
/**
200207
* Return the charset that the {@link #getValue() } and {@link #setValue(java.lang.String)
201208
* } functions will use to convert to/from string/byte data buffer.
202-
*
209+
*
203210
* @return The charset.
204211
*/
205212
public Charset getCharset() {
206213
return this.charset;
207214
}
215+
216+
/**
217+
* Return the value retrieve method used by this String data request.
218+
*
219+
* @return Value retrieve method.
220+
*/
221+
public ValueRetrieveMethod getValueRetrieveMethod() {
222+
return valueRetrieveMethod;
223+
}
224+
225+
/**
226+
* Sets the value retrieve method for this String data request.
227+
*
228+
* @param valueRetrieveMethod Value retrieve method.
229+
*/
230+
public void setValueRetrieveMethod(ValueRetrieveMethod valueRetrieveMethod) {
231+
this.valueRetrieveMethod = valueRetrieveMethod;
232+
}
233+
234+
/**
235+
* This enumeration defines values retrieve method that will be used by {@link #getValue() } method.
236+
*/
237+
public enum ValueRetrieveMethod {
238+
/**
239+
* Retrieve the content of whole underlying byte buffer when converting it to String.
240+
*/
241+
WHOLE_BUFFER,
242+
/**
243+
* Retrieve the content of underlying byte buffer up to first zero byte when converting it to String.
244+
*/
245+
TO_FIRST_ZERO_BYTE
246+
}
208247
}

FSUIPC/src/com/mouseviator/fsuipc/helpers/LuaHelper.java

+3
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ private LuaResult runLuaCommandOnce(FSUIPC fsuipc, String luaProgram, int luaPar
547547
*/
548548
public static class LuaControlRequest extends DataRequest implements IWriteOnlyRequest<String> {
549549

550+
/**
551+
* This character si used to separate command and arguments when working with lua programs via FSUIPC
552+
*/
550553
public static final String COMMAND_SEPARATOR = ":";
551554

552555
private LuaControlRequestCommand command;

FSUIPC/src/com/mouseviator/fsuipc/helpers/MacroHelper.java

+3
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ public MacroResult executeMacro(String macroFile, String macroName, int macroPar
380380
*/
381381
public static class MacroExecuteRequest extends DataRequest implements IWriteOnlyRequest<String> {
382382

383+
/**
384+
* This character is used to separate macro file name and macro name when calling macro using FSUIPC
385+
*/
383386
public static final char MACRO_SEPARATOR = ':';
384387
private static final byte MAX_MACRO_FILE_LENGHT = 16;
385388
private static final byte MAX_MACRO_NAME_LENGTH = 16;

FSUIPC/version.properties

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2009 Richard Nichols.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# under the License.
15+
16+
project.version=1.0.2

FSUIPCAircraftMonitor/nbproject/build-impl.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ is divided into following sections:
17231723
</target>
17241724
<target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
17251725
<target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/>
1726+
<target depends="debug-test-method" name="debug-single-method"/>
17261727
<target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
17271728
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
17281729
</target>

FSUIPCAircraftMonitor/nbproject/genfiles.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ [email protected]
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
66
nbproject/build-impl.xml.data.CRC32=a35a9ee1
7-
nbproject/build-impl.xml.script.CRC32=95f32761
8-
nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.95.0.48
7+
nbproject/build-impl.xml.script.CRC32=de977d64
8+
nbproject/build-impl.xml.stylesheet.CRC32=d549e5cc@1.97.0.48

FSUIPCAircraftMonitor/nbproject/private/private.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ do.jlink=false
55
javac.debug=true
66
javadoc.preview=true
77
jlink.strip=false
8-
user.properties.file=C:\\Users\\Murdock\\AppData\\Roaming\\NetBeans\\12.1\\build.properties
8+
user.properties.file=C:\\Users\\Murdock\\AppData\\Roaming\\NetBeans\\12.2\\build.properties
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)