/* * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Update these settings with {@code data} obtained from * XSETTINGS manager. * * @param data settings data obtained from * {@code _XSETTINGS_SETTINGS} window property of the * settings manager. * @return a {@code Map} of changed settings.
*/ public Map<String, Object> update(byte[] data) { return (new Update(data)).update();
}
/** * TBS ...
*/ class Update {
/* byte order mark */ privatestaticfinalint LITTLE_ENDIAN = 0; privatestaticfinalint BIG_ENDIAN = 1;
/** * Construct an Update object for the data read from * {@code _XSETTINGS_SETTINGS} property of the XSETTINGS * selection owner. * * @param data {@code _XSETTINGS_SETTINGS} contents.
*/
Update(byte[] data) { this.data = data;
// first byte gives endianness of the data // next 3 bytes are unused (pad to 32 bit)
idx = 0;
isLittle = (getCARD8() == LITTLE_ENDIAN);
idx = 4;
serial = getCARD32();
// N_SETTINGS is actually CARD32 (i.e. unsigned), but // since java doesn't have an unsigned int type, and // N_SETTINGS cannot realistically exceed 2^31 (so we // gonna use int anyway), just read it as INT32.
idx = 8;
nsettings = getINT32();
updatedSettings = new HashMap<>();
isValid = true;
}
privatevoid needBytes(int n) throws IndexOutOfBoundsException
{ if (idx + n <= dlen) { return;
}
thrownew IndexOutOfBoundsException("at " + idx
+ " need " + n
+ " length " + dlen);
}
/** * Update settings.
*/ public Map<String, Object> update() { if (!isValid) { returnnull;
}
synchronized (XSettings.this) { long currentSerial = XSettings.this.serial;
if (this.serial <= currentSerial) { returnnull;
}
for (int i = 0; i < nsettings && idx < dlen; ++i) {
updateOne(currentSerial);
}
XSettings.this.serial = this.serial;
}
return updatedSettings;
}
/** * Parses a particular x setting. * * @exception IndexOutOfBoundsException if there isn't enough * data for a setting.
*/ privatevoid updateOne(long currentSerial) throws IndexOutOfBoundsException,
IllegalArgumentException
{ int type = getCARD8();
++idx; // pad to next CARD16
// save position of the property name, skip to serial int nameLen = getCARD16(); int nameIdx = idx;
// check if we should bother
idx = (idx + nameLen + 3) & ~0x3; // pad to 32 bit long lastChanged = getCARD32();
// Avoid constructing garbage for properties that has not // changed, skip the data for this property. if (lastChanged <= currentSerial) { // skip if (type == TYPE_INTEGER) {
idx += 4;
} elseif (type == TYPE_STRING) { int len = getINT32();
idx = (idx + len + 3) & ~0x3;
} elseif (type == TYPE_COLOR) {
idx += 8; // 4 CARD16
} else { thrownew IllegalArgumentException("Unknown type: "
+ type);
}
Object value = null; if (type == TYPE_INTEGER) {
value = Integer.valueOf(getINT32());
} elseif (type == TYPE_STRING) {
value = getString(getINT32());
} elseif (type == TYPE_COLOR) { int r = getCARD16(); int g = getCARD16(); int b = getCARD16(); int a = getCARD16();
value = new Color(r / 65535.0f,
g / 65535.0f,
b / 65535.0f,
a / 65535.0f);
} else { thrownew IllegalArgumentException("Unknown type: " + type);
}
if (name == null) { // dtrace??? return;
}
updatedSettings.put(name, value);
}
} // class XSettings.Update
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.