JVM property -Dfile.encoding=UTF8 or UTF-8? - file

I would like to know what is the value of the Java Virtual Machine (JVM) property to set my file encoding to UTF-8.
Do I put -Dfile.encoding=UTF8 or -Dfile.encoding=UTF-8?

It will be:
UTF8
See here for the definitions.

If, running an Oracle HotSpot JDK 1.7.x, on a Linux platform where your locale suggests UTF-8 (e.g. LANG=en_US.utf8), if you don't set it on the command-line with -Dfile.encoding, the JDK will default file.encoding and the default Charset like this:
System.out.println(String.format("file.encoding: %s", System.getProperty("file.encoding")));
System.out.println(String.format("defaultCharset: %s", Charset.defaultCharset().name()));
... yields:
file.encoding: UTF-8
defaultCharset: UTF-8
... suggesting the default is UTF-8 on such a platform.
Additionally, if java.nio.charset.Charset.defaultCharset() finds file.encoding not-set, it looks for java.nio.charset.Charset.forName("UTF-8"), suggesting it prefers that string, although it is well-aliased, so "UTF8" will also work fine.
If you run the same program on the same platform with java -Dfile.encoding=UTF8, without the hypen, it yields:
file.encoding: UTF8
defaultCharset: UTF-8
... noting that the default charset has been canonicalized from UTF8 to UTF-8.

Both UTF8 and UTF-8 work for me.

[INFO] BUILD SUCCESS
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Anyway, it works for me:)

This is not a direct answer, but very useful if you don't have access to how java starts: you can set the environment variable JAVA_TOOLS_OPTIONS to -Dfile.encoding="UTF-8" and every time the jvm starts it will pick up that option.

Related

In c printf format of numbers will nor work in mrsh

Using printf format in for numbers which will work fine:
printf ("\r\n <%s>\t AmountOfMalloc %'.ld", HostName ,GetMalloc ()) ;
Output is like this, which is fine:
AmountOfMalloc 17.220.149.424
Calling the same app remote via mrsh in a script will cause no number format like this:
AmountOfMalloc 17220149424
Envirenment is Suse Linux Enterprise Server 15 sp2 in VMware Workstation 15.5.7 on Windows 10 ltsc 2019, 4 cores, 6GB ram.
Has someone expierienced this issue and a possible solution?
The difference is caused by different environment locale settings.
You can see the settings that are applied when the program runs the way you want by running locale command. It will output several lines for e.g. money and number format settings, but usually they all have the same value, such as "en_US.UTF-8".
Easiest way to apply the setting to your remotely run command is to prefix the line like this:
LC_ALL=en_US.UTF-8 /path/to/program
From the examples you provide, the locale you want is probably different than en_US.UTF-8, so use the value you get from locale.
Thanks a lot, locale was the problem. Did not see any reason why,
Adding the following to the c source before printf works fine:
setlocale ( LC_NUMERIC, "de_DE.UTF-8" ) ;
setlocale ( LC_ALL, "de_DE.UTF-8" ) ;
Thanks.

shp2pgsql dumping double fields with comma separator instead of dot

I guess the source shapefile is the culprit, but is there any way to change to fix it through shp2pgsql?
Obviously Postgres throw an error with:
INSERT INTO "public"."a" ("area","perimeter", ...) VALUES ('5282,98830007762','313,033597376014', ...);
EDIT:
I'm not entirely sure, but I think this is solved if you connect putty from a computer with an English OS
It seems you have a locale that formats floating points with a comma. Try setting the environment variable LC_NUMERIC=C. E.g.:
$ LC_NUMERIC=C shp2pgsql myshp.shp > myshp.sql
In my case it was solved by:
export LANG=en.UTF8
shp2pgsql myshp.shp > myshp.sql

Why won't mariadb listen on port 3306 after a macports update?

At some point after a mariadb port update, she refused to listen on 3306 upon startup.
I made sure there were no skip-networking directives, and even tried adding one with "=OFF", which did nothing... but the odd thing was it had been working, and "I haven't changed anything".
Yet when I run:
/opt/local/lib/mariadb/bin/mysqladmin variables -u root -p | grep skip_networking
I see skip-networking as being ON.
My config has this:
[mysqld]
port = 3306
bind-address = 127.0.0.1
and no skip-networking setting at all.
Even passing the port and bind-address via command line will not make it listen.
After a grep of /opt/local/etc, it turns out there is a default config, and inside that there's a skip-networking directive:
cat /opt/local/etc/mariadb/macports-default.cnf
This was only picked up because after reading /etc/my.cnf, apparently the /opt/local/etc/mariadb/my.cnf file is also read. (I'd used /etc/my.cnf, never having edited the other, but something changed-- maybe I'd edited the default and it was overwritten with the update, though I don't remember doing so.)
Commenting out the include in /opt/local/etc/mariadb/my.cnf of the macports-default.cnf once again has her listening.
Pretty clear solution in retrospect I guess, but I was a bit stumped, as I swear "I changed nothing!"... Regardless-- For posterity, and key word searches!
I can't comment yet, but wanted to add:
If you have other versions of MySQL or mariaDB installed via MacPorts, be sure to check out their config files too because MariaDB reads them.
Locations:
/opt/local/etc/mysql${mysqlVersion}/my.cnf
/opt/local/etc/mariadb-${mariadbVersion}/my.cnf
I have mariadb-10.1-server installed. There are two configs:
/opt/local/etc/mariadb/my.cnf
/opt/local/etc/mariadb-${mariadbVersion}/my.cnf
Additionally, some info about default config files from MirandaDB documentation (this is not Macports specific):
/etc/my.cnf
/etc/mysql/my.cnf
my.cnf in the DEFAULT_SYSCONFDIR specified during the compilation
my.cnf in the path, specified in the environment variable MYSQL_HOME (if any) the file specified in --defaults-extra-file (if any)
user-home-dir/.my.cnf
Alternatively to commenting out the defaults file, the value can be overriden in the my.cnf:
[mysqld]
...
skip_networking=0

Python 3: reading UCS-2 (BE) file

I can't seem to be able to decode UCS-2 BE files (legacy stuff) under Python 3.3, using the built-in open() function (stack trace shows UnicodeDecodeError and contains my readLine() method) - in fact, I wasn't able to find a flag for specifying this encoding.
Using Windows 8, terminal is set to codepage 65001, using 'Lucida Console' fonts.
Code snippet won't be of too much help, I guess:
def display_resource():
f = open(r'D:\workspace\resources\JP.res', encoding=<??tried_several??>)
while True:
line = f.readline()
if len(line) == 0:
break
Appreciating any insight into this issue.
UCS-2 is UTF-16, really, for any codepoint that was assigned when it was still called UCS-2 in any case.
Open it with encoding='utf16'. If there is no BOM (the Byte order mark, 2 bytes at the start, for BE that'd be \xfe\xff), then use encoding='utf_16_be' to force a byte order.

How to get os name, version in windows?

Which one is better in following aspects to get OS name, OS version in windows -
time in getting information
compatibility in all windows OS like xp, vista and higher
systeminfo or wmic command? I wanted to avoid the use of OSVersionInfoEx in C as one has to hardcode the marketing name detection and will add to maintenance work if new flavour of windows gets introduced. Please share your opinion.
GetVersionEx - You can't get any faster than this for getting a basic os version number. But you are right, you won't be able to map newer versions of the OS to the correct string. Have you considered just doing this:
OSVERSIONINFOEX version = {};
char szOS[MAX_OS_LENGTH];
version.dwOSVersionInfoSize = sizeof(version);
GetVersionEx((OSVERSIONINFO*)&version);
if (MyFunctionToMapVersionToString(&version, szOS) == false)
{
sprintf(szOS, "Microsoft Windows %d.%d", version.dwMajorVersion, version.dwMinorVersion);
}
WMI - A bit more code to write. But you could likely just do this at app startup (or when it's needed) and cache the result if the information is needed again. It's not like the operating system product name will change after the app has queried for it once. :) As to backwards compatibility, I'm sure it work fine on older operating systems... but you are going to test it before shipping it to the customer, right?
If you want an undocumented way, there is a registry key that has exactly what you want in it:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion ("ProductName")

Resources