Search in sources :

Example 11 with PlatformLogger

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

the class SourceClassName method writeLogRecords.

private static void writeLogRecords(PrintStream logps) throws Exception {
    PrintStream err = System.err;
    try {
        System.setErr(logps);
        Object[] params = new Object[] { new Long(1), "string" };
        PlatformLogger plog = PlatformLogger.getLogger("test.log.foo");
        plog.severe("Log message {0} {1}", (Object[]) params);
        // create a java.util.logging.Logger
        // now java.util.logging.Logger should be created for each platform logger
        Logger logger = Logger.getLogger("test.log.bar");
        logger.log(Level.SEVERE, "Log message {0} {1}", params);
        plog.severe("Log message {0} {1}", (Object[]) params);
    } finally {
        logps.flush();
        logps.close();
        System.setErr(err);
    }
}
Also used : PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger)

Example 12 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 13 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 14 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