Search in sources :

Example 6 with PlatformLogger

use of sun.util.logging.PlatformLogger in project jdk8u_jdk by JetBrains.

the class X11FontManager method registerFontDir.

/* NOTE: this method needs to be executed in a privileged context.
     * The superclass constructor which is the primary caller of
     * this method executes entirely in such a context. Additionally
     * the loadFonts() method does too. So all should be well.

     */
@Override
protected void registerFontDir(String path) {
    /* fonts.dir file format looks like :-
         * 47
         * Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1
         * Arial-Bold.ttf -monotype-arial-bold-r-normal--0-0-0-0-p-0-iso8859-1
         * ...
         */
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger().info("ParseFontDir " + path);
    }
    File fontsDotDir = new File(path + File.separator + "fonts.dir");
    FileReader fr = null;
    try {
        if (fontsDotDir.canRead()) {
            fr = new FileReader(fontsDotDir);
            BufferedReader br = new BufferedReader(fr, 8192);
            StreamTokenizer st = new StreamTokenizer(br);
            st.eolIsSignificant(true);
            int ttype = st.nextToken();
            if (ttype == StreamTokenizer.TT_NUMBER) {
                int numEntries = (int) st.nval;
                ttype = st.nextToken();
                if (ttype == StreamTokenizer.TT_EOL) {
                    st.resetSyntax();
                    st.wordChars(32, 127);
                    st.wordChars(128 + 32, 255);
                    st.whitespaceChars(0, 31);
                    for (int i = 0; i < numEntries; i++) {
                        ttype = st.nextToken();
                        if (ttype == StreamTokenizer.TT_EOF) {
                            break;
                        }
                        if (ttype != StreamTokenizer.TT_WORD) {
                            break;
                        }
                        int breakPos = st.sval.indexOf(' ');
                        if (breakPos <= 0) {
                            /* On TurboLinux 8.0 a fonts.dir file had
                                 * a line with integer value "24" which
                                 * appeared to be the number of remaining
                                 * entries in the file. This didn't add to
                                 * the value on the first line of the file.
                                 * Seemed like XFree86 didn't like this line
                                 * much either. It failed to parse the file.
                                 * Ignore lines like this completely, and
                                 * don't let them count as an entry.
                                 */
                            numEntries++;
                            ttype = st.nextToken();
                            if (ttype != StreamTokenizer.TT_EOL) {
                                break;
                            }
                            continue;
                        }
                        if (st.sval.charAt(0) == '!') {
                            /* TurboLinux 8.0 comment line: ignore.
                                 * can't use st.commentChar('!') to just
                                 * skip because this line mustn't count
                                 * against numEntries.
                                 */
                            numEntries++;
                            ttype = st.nextToken();
                            if (ttype != StreamTokenizer.TT_EOL) {
                                break;
                            }
                            continue;
                        }
                        String fileName = st.sval.substring(0, breakPos);
                        /* TurboLinux 8.0 uses some additional syntax to
                             * indicate algorithmic styling values.
                             * Ignore ':' separated files at the beginning
                             * of the fileName
                             */
                        int lastColon = fileName.lastIndexOf(':');
                        if (lastColon > 0) {
                            if (lastColon + 1 >= fileName.length()) {
                                continue;
                            }
                            fileName = fileName.substring(lastColon + 1);
                        }
                        String fontPart = st.sval.substring(breakPos + 1);
                        String fontID = specificFontIDForName(fontPart);
                        String sVal = (String) fontNameMap.get(fontID);
                        if (FontUtilities.debugFonts()) {
                            PlatformLogger logger = FontUtilities.getLogger();
                            logger.info("file=" + fileName + " xlfd=" + fontPart);
                            logger.info("fontID=" + fontID + " sVal=" + sVal);
                        }
                        String fullPath = null;
                        try {
                            File file = new File(path, fileName);
                            /* we may have a resolved symbolic link
                                 * this becomes important for an xlfd we
                                 * still need to know the location it was
                                 * found to update the X server font path
                                 * for use by AWT heavyweights - and when 2D
                                 * wants to use the native rasteriser.
                                 */
                            if (xFontDirsMap == null) {
                                xFontDirsMap = new HashMap();
                            }
                            xFontDirsMap.put(fontID, path);
                            fullPath = file.getCanonicalPath();
                        } catch (IOException e) {
                            fullPath = path + File.separator + fileName;
                        }
                        Vector xVal = (Vector) xlfdMap.get(fullPath);
                        if (FontUtilities.debugFonts()) {
                            FontUtilities.getLogger().info("fullPath=" + fullPath + " xVal=" + xVal);
                        }
                        if ((xVal == null || !xVal.contains(fontPart)) && (sVal == null) || !sVal.startsWith("/")) {
                            if (FontUtilities.debugFonts()) {
                                FontUtilities.getLogger().info("Map fontID:" + fontID + "to file:" + fullPath);
                            }
                            fontNameMap.put(fontID, fullPath);
                            if (xVal == null) {
                                xVal = new Vector();
                                xlfdMap.put(fullPath, xVal);
                            }
                            xVal.add(fontPart);
                        }
                        ttype = st.nextToken();
                        if (ttype != StreamTokenizer.TT_EOL) {
                            break;
                        }
                    }
                }
            }
            fr.close();
        }
    } catch (IOException ioe1) {
    } finally {
        if (fr != null) {
            try {
                fr.close();
            } catch (IOException ioe2) {
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PlatformLogger(sun.util.logging.PlatformLogger) File(java.io.File) Vector(java.util.Vector) StreamTokenizer(java.io.StreamTokenizer)

Example 7 with PlatformLogger

use of sun.util.logging.PlatformLogger in project jdk8u_jdk by JetBrains.

the class FontConfigManager method initFontConfigFonts.

/* This can be made public if it's needed to force a re-read
     * rather than using the cached values. The re-read would be needed
     * only if some event signalled that the fontconfig has changed.
     * In that event this method would need to return directly the array
     * to be used by the caller in case it subsequently changed.
     */
public synchronized void initFontConfigFonts(boolean includeFallbacks) {
    if (fontConfigFonts != null) {
        if (!includeFallbacks || (fontConfigFonts[0].allFonts != null)) {
            return;
        }
    }
    if (FontUtilities.isWindows || fontConfigFailed) {
        return;
    }
    long t0 = 0;
    if (FontUtilities.isLogging()) {
        t0 = System.nanoTime();
    }
    FcCompFont[] fontArr = new FcCompFont[fontConfigNames.length];
    for (int i = 0; i < fontArr.length; i++) {
        fontArr[i] = new FcCompFont();
        fontArr[i].fcName = fontConfigNames[i];
        int colonPos = fontArr[i].fcName.indexOf(':');
        fontArr[i].fcFamily = fontArr[i].fcName.substring(0, colonPos);
        fontArr[i].jdkName = FontUtilities.mapFcName(fontArr[i].fcFamily);
        // depends on array order.
        fontArr[i].style = i % 4;
    }
    getFontConfig(getFCLocaleStr(), fcInfo, fontArr, includeFallbacks);
    FontConfigFont anyFont = null;
    /* If don't find anything (eg no libfontconfig), then just return */
    for (int i = 0; i < fontArr.length; i++) {
        FcCompFont fci = fontArr[i];
        if (fci.firstFont == null) {
            if (FontUtilities.isLogging()) {
                PlatformLogger logger = FontUtilities.getLogger();
                logger.info("Fontconfig returned no font for " + fontArr[i].fcName);
            }
            fontConfigFailed = true;
        } else if (anyFont == null) {
            anyFont = fci.firstFont;
        }
    }
    if (anyFont == null) {
        if (FontUtilities.isLogging()) {
            PlatformLogger logger = FontUtilities.getLogger();
            logger.info("Fontconfig returned no fonts at all.");
        }
        fontConfigFailed = true;
        return;
    } else if (fontConfigFailed) {
        for (int i = 0; i < fontArr.length; i++) {
            if (fontArr[i].firstFont == null) {
                fontArr[i].firstFont = anyFont;
            }
        }
    }
    fontConfigFonts = fontArr;
    if (FontUtilities.isLogging()) {
        PlatformLogger logger = FontUtilities.getLogger();
        long t1 = System.nanoTime();
        logger.info("Time spent accessing fontconfig=" + ((t1 - t0) / 1000000) + "ms.");
        for (int i = 0; i < fontConfigFonts.length; i++) {
            FcCompFont fci = fontConfigFonts[i];
            logger.info("FC font " + fci.fcName + " maps to family " + fci.firstFont.familyName + " in file " + fci.firstFont.fontFile);
            if (fci.allFonts != null) {
                for (int f = 0; f < fci.allFonts.length; f++) {
                    FontConfigFont fcf = fci.allFonts[f];
                    logger.info("Family=" + fcf.familyName + " Style=" + fcf.styleStr + " Fullname=" + fcf.fullName + " File=" + fcf.fontFile);
                }
            }
        }
    }
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger)

Example 8 with PlatformLogger

use of sun.util.logging.PlatformLogger in project jdk8u_jdk by JetBrains.

the class CookieManager method put.

public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException {
    // pre-condition check
    if (uri == null || responseHeaders == null) {
        throw new IllegalArgumentException("Argument is null");
    }
    // if there's no default CookieStore, no need to remember any cookie
    if (cookieJar == null)
        return;
    PlatformLogger logger = PlatformLogger.getLogger("java.net.CookieManager");
    for (String headerKey : responseHeaders.keySet()) {
        // we also accept 'Set-Cookie' here for backward compatibility
        if (headerKey == null || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) {
            continue;
        }
        for (String headerValue : responseHeaders.get(headerKey)) {
            try {
                List<HttpCookie> cookies;
                try {
                    cookies = HttpCookie.parse(headerValue);
                } catch (IllegalArgumentException e) {
                    // Bogus header, make an empty list and log the error
                    cookies = java.util.Collections.emptyList();
                    if (logger.isLoggable(PlatformLogger.Level.SEVERE)) {
                        logger.severe("Invalid cookie for " + uri + ": " + headerValue);
                    }
                }
                for (HttpCookie cookie : cookies) {
                    if (cookie.getPath() == null) {
                        // If no path is specified, then by default
                        // the path is the directory of the page/doc
                        String path = uri.getPath();
                        if (!path.endsWith("/")) {
                            int i = path.lastIndexOf("/");
                            if (i > 0) {
                                path = path.substring(0, i + 1);
                            } else {
                                path = "/";
                            }
                        }
                        cookie.setPath(path);
                    }
                    // the default Domain can only domain-match itself.)
                    if (cookie.getDomain() == null) {
                        String host = uri.getHost();
                        if (host != null && !host.contains("."))
                            host += ".local";
                        cookie.setDomain(host);
                    }
                    String ports = cookie.getPortlist();
                    if (ports != null) {
                        int port = uri.getPort();
                        if (port == -1) {
                            port = "https".equals(uri.getScheme()) ? 443 : 80;
                        }
                        if (ports.isEmpty()) {
                            // Empty port list means this should be restricted
                            // to the incoming URI port
                            cookie.setPortlist("" + port);
                            if (shouldAcceptInternal(uri, cookie)) {
                                cookieJar.add(uri, cookie);
                            }
                        } else {
                            // RFC 2965 section 3.3.2
                            if (isInPortList(ports, port) && shouldAcceptInternal(uri, cookie)) {
                                cookieJar.add(uri, cookie);
                            }
                        }
                    } else {
                        if (shouldAcceptInternal(uri, cookie)) {
                            cookieJar.add(uri, cookie);
                        }
                    }
                }
            } catch (IllegalArgumentException e) {
            // invalid set-cookie header string
            // no-op
            }
        }
    }
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger)

Example 9 with PlatformLogger

use of sun.util.logging.PlatformLogger in project jdk8u_jdk by JetBrains.

the class HijrahChronology method loadCalendarData.

/**
     * Loads and processes the Hijrah calendar properties file for this calendarType.
     * The starting Hijrah date and the corresponding ISO date are
     * extracted and used to calculate the epochDate offset.
     * The version number is identified and ignored.
     * Everything else is the data for a year with containing the length of each
     * of 12 months.
     *
     * @throws DateTimeException if initialization of the calendar data from the
     *     resource fails
     */
private void loadCalendarData() {
    try {
        String resourceName = calendarProperties.getProperty(PROP_PREFIX + typeId);
        Objects.requireNonNull(resourceName, "Resource missing for calendar: " + PROP_PREFIX + typeId);
        Properties props = readConfigProperties(resourceName);
        Map<Integer, int[]> years = new HashMap<>();
        int minYear = Integer.MAX_VALUE;
        int maxYear = Integer.MIN_VALUE;
        String id = null;
        String type = null;
        String version = null;
        int isoStart = 0;
        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            String key = (String) entry.getKey();
            switch(key) {
                case KEY_ID:
                    id = (String) entry.getValue();
                    break;
                case KEY_TYPE:
                    type = (String) entry.getValue();
                    break;
                case KEY_VERSION:
                    version = (String) entry.getValue();
                    break;
                case KEY_ISO_START:
                    {
                        int[] ymd = parseYMD((String) entry.getValue());
                        isoStart = (int) LocalDate.of(ymd[0], ymd[1], ymd[2]).toEpochDay();
                        break;
                    }
                default:
                    try {
                        // Everything else is either a year or invalid
                        int year = Integer.valueOf(key);
                        int[] months = parseMonths((String) entry.getValue());
                        years.put(year, months);
                        maxYear = Math.max(maxYear, year);
                        minYear = Math.min(minYear, year);
                    } catch (NumberFormatException nfe) {
                        throw new IllegalArgumentException("bad key: " + key);
                    }
            }
        }
        if (!getId().equals(id)) {
            throw new IllegalArgumentException("Configuration is for a different calendar: " + id);
        }
        if (!getCalendarType().equals(type)) {
            throw new IllegalArgumentException("Configuration is for a different calendar type: " + type);
        }
        if (version == null || version.isEmpty()) {
            throw new IllegalArgumentException("Configuration does not contain a version");
        }
        if (isoStart == 0) {
            throw new IllegalArgumentException("Configuration does not contain a ISO start date");
        }
        // Now create and validate the array of epochDays indexed by epochMonth
        hijrahStartEpochMonth = minYear * 12;
        minEpochDay = isoStart;
        hijrahEpochMonthStartDays = createEpochMonths(minEpochDay, minYear, maxYear, years);
        maxEpochDay = hijrahEpochMonthStartDays[hijrahEpochMonthStartDays.length - 1];
        // Compute the min and max year length in days.
        for (int year = minYear; year < maxYear; year++) {
            int length = getYearLength(year);
            minYearLength = Math.min(minYearLength, length);
            maxYearLength = Math.max(maxYearLength, length);
        }
    } catch (Exception ex) {
        // Log error and throw a DateTimeException
        PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
        logger.severe("Unable to initialize Hijrah calendar proxy: " + typeId, ex);
        throw new DateTimeException("Unable to initialize HijrahCalendar: " + typeId, ex);
    }
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) InvalidObjectException(java.io.InvalidObjectException) DateTimeException(java.time.DateTimeException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) DateTimeException(java.time.DateTimeException) PlatformLogger(sun.util.logging.PlatformLogger) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with PlatformLogger

use of sun.util.logging.PlatformLogger in project jdk8u_jdk by JetBrains.

the class AbstractChronology method initCache.

/**
     * Initialization of the maps from id and type to Chronology.
     * The ServiceLoader is used to find and register any implementations
     * of {@link java.time.chrono.AbstractChronology} found in the bootclass loader.
     * The built-in chronologies are registered explicitly.
     * Calendars configured via the Thread's context classloader are local
     * to that thread and are ignored.
     * <p>
     * The initialization is done only once using the registration
     * of the IsoChronology as the test and the final step.
     * Multiple threads may perform the initialization concurrently.
     * Only the first registration of each Chronology is retained by the
     * ConcurrentHashMap.
     * @return true if the cache was initialized
     */
private static boolean initCache() {
    if (CHRONOS_BY_ID.get("ISO") == null) {
        // Initialization is incomplete
        // Register built-in Chronologies
        registerChrono(HijrahChronology.INSTANCE);
        registerChrono(JapaneseChronology.INSTANCE);
        registerChrono(MinguoChronology.INSTANCE);
        registerChrono(ThaiBuddhistChronology.INSTANCE);
        // Register Chronologies from the ServiceLoader
        @SuppressWarnings("rawtypes") ServiceLoader<AbstractChronology> loader = ServiceLoader.load(AbstractChronology.class, null);
        for (AbstractChronology chrono : loader) {
            String id = chrono.getId();
            if (id.equals("ISO") || registerChrono(chrono) != null) {
                // Log the attempt to replace an existing Chronology
                PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
                logger.warning("Ignoring duplicate Chronology, from ServiceLoader configuration " + id);
            }
        }
        // finally, register IsoChronology to mark initialization is complete
        registerChrono(IsoChronology.INSTANCE);
        return true;
    }
    return false;
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger)

Aggregations

PlatformLogger (sun.util.logging.PlatformLogger)14 Level (sun.util.logging.PlatformLogger.Level)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 InvalidObjectException (java.io.InvalidObjectException)1 StreamTokenizer (java.io.StreamTokenizer)1 PrivilegedActionException (java.security.PrivilegedActionException)1 MessageFormat (java.text.MessageFormat)1 DateTimeException (java.time.DateTimeException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Vector (java.util.Vector)1