List of usage examples for java.util Locale ROOT
Locale ROOT
To view the source code for java.util Locale ROOT.
Click Source Link
From source file:com.puppycrawl.tools.checkstyle.MainTest.java
@Test public void testNonExistingConfigFile() throws Exception { exit.expectSystemExitWithStatus(-2); exit.checkAssertionAfterwards(new Assertion() { @Override/*from w w w . j a va 2 s . c om*/ public void checkAssertion() { assertEquals( String.format(Locale.ROOT, "Unable to find: src/main/resources/non_existing_config.xml%n" + "Checkstyle ends with 1 errors.%n"), systemOut.getLog()); assertEquals("", systemErr.getLog()); } }); Main.main("-c", "src/main/resources/non_existing_config.xml", "src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java"); }
From source file:jgnash.report.pdf.Report.java
private PDFont loadFont(final String name, final PDDocument document) { final String path = FontRegistry.getRegisteredFontPath(name); if (path != null && !path.isEmpty()) { try {/*from ww w .ja v a 2s . c o m*/ if (path.toLowerCase(Locale.ROOT).endsWith(".ttf") || path.toLowerCase(Locale.ROOT).endsWith(".otf") || path.toLowerCase(Locale.ROOT).indexOf(".ttc,") > 0) { return PDType0Font.load(document, new FileInputStream(path), false); } else if (path.toLowerCase(Locale.ROOT).endsWith(".afm") || path.toLowerCase(Locale.ROOT).endsWith(".pfm")) { return new PDType1Font(document, new FileInputStream(path)); } } catch (final Exception ignored) { } } return PDType1Font.COURIER; }
From source file:net.yacy.crawler.retrieval.HTTPLoader.java
/** * Open an input stream on a requested HTTP resource. When the resource content size is small * (lower than {@link Response#CRAWLER_MAX_SIZE_TO_CACHE}, fully load it and use a ByteArrayInputStream instance. * @param request/*w ww. j a v a2 s. c o m*/ * @param profile crawl profile * @param retryCount remaining redirect retries count * @param maxFileSize max file size to load. -1 means no limit. * @param blacklistType blacklist type to use * @param agent agent identifier * @return a response with full meta data and embedding on open input stream on content. Don't forget to close the stream. * @throws IOException when an error occurred */ public StreamResponse openInputStream(final Request request, CrawlProfile profile, final int retryCount, final int maxFileSize, final BlacklistType blacklistType, final ClientIdentification.Agent agent) throws IOException { if (retryCount < 0) { this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile, FailCategory.TEMPORARY_NETWORK_FAILURE, "retry counter exceeded", -1); throw new IOException( "retry counter exceeded for URL " + request.url().toString() + ". Processing aborted.$"); } DigestURL url = request.url(); final String host = url.getHost(); if (host == null || host.length() < 2) { throw new IOException("host is not well-formed: '" + host + "'"); } final String path = url.getFile(); int port = url.getPort(); final boolean ssl = url.getProtocol().equals("https"); if (port < 0) port = (ssl) ? 443 : 80; // check if url is in blacklist final String hostlow = host.toLowerCase(Locale.ROOT); if (blacklistType != null && Switchboard.urlBlacklist.isListed(blacklistType, hostlow, path)) { this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile, FailCategory.FINAL_LOAD_CONTEXT, "url in blacklist", -1); throw new IOException( "CRAWLER Rejecting URL '" + request.url().toString() + "'. URL is in blacklist.$"); } // resolve yacy and yacyh domains final AlternativeDomainNames yacyResolver = this.sb.peers; if (yacyResolver != null) { final String yAddress = yacyResolver.resolve(host); if (yAddress != null) { url = new DigestURL(url.getProtocol() + "://" + yAddress + path); } } // create a request header final RequestHeader requestHeader = createRequestheader(request, agent); // HTTP-Client final HTTPClient client = new HTTPClient(agent); client.setRedirecting(false); // we want to handle redirection // ourselves, so we don't index pages // twice client.setTimout(this.socketTimeout); client.setHeader(requestHeader.entrySet()); // send request client.GET(url, false); final StatusLine statusline = client.getHttpResponse().getStatusLine(); final int statusCode = statusline.getStatusCode(); final ResponseHeader responseHeader = new ResponseHeader(statusCode, client.getHttpResponse().getAllHeaders()); String requestURLString = request.url().toNormalform(true); // check redirection if (statusCode > 299 && statusCode < 310) { client.finish(); final DigestURL redirectionUrl = extractRedirectURL(request, profile, url, statusline, responseHeader, requestURLString); if (this.sb.getConfigBool(SwitchboardConstants.CRAWLER_FOLLOW_REDIRECTS, true)) { // we have two use cases here: loading from a crawl or just // loading the url. Check this: if (profile != null && !CrawlSwitchboard.DEFAULT_PROFILES.contains(profile.name())) { // put redirect url on the crawler queue to repeat a // double-check /* We have to clone the request instance and not to modify directly its URL, * otherwise the stackCrawl() function would reject it, because detecting it as already in the activeWorkerEntries */ Request redirectedRequest = new Request(request.initiator(), redirectionUrl, request.referrerhash(), request.name(), request.appdate(), request.profileHandle(), request.depth(), request.timezoneOffset()); String rejectReason = this.sb.crawlStacker.stackCrawl(redirectedRequest); if (rejectReason != null) { throw new IOException("CRAWLER Redirect of URL=" + requestURLString + " aborted. Reason : " + rejectReason); } // in the end we must throw an exception (even if this is // not an error, just to abort the current process throw new IOException("CRAWLER Redirect of URL=" + requestURLString + " to " + redirectionUrl.toNormalform(false) + " placed on crawler queue for double-check"); } // if we are already doing a shutdown we don't need to retry // crawling if (Thread.currentThread().isInterrupted()) { this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile, FailCategory.FINAL_LOAD_CONTEXT, "server shutdown", statusCode); throw new IOException("CRAWLER Redirect of URL=" + requestURLString + " aborted because of server shutdown.$"); } // retry crawling with new url request.redirectURL(redirectionUrl); return openInputStream(request, profile, retryCount - 1, maxFileSize, blacklistType, agent); } // we don't want to follow redirects this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile, FailCategory.FINAL_PROCESS_CONTEXT, "redirection not wanted", statusCode); throw new IOException( "REJECTED UNWANTED REDIRECTION '" + statusline + "' for URL '" + requestURLString + "'$"); } else if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION) { // the transfer is ok /* * When content is not large (less than Response.CRAWLER_MAX_SIZE_TO_CACHE), we have better cache it if cache is enabled and url is not local */ long contentLength = client.getHttpResponse().getEntity().getContentLength(); InputStream contentStream; if (profile != null && profile.storeHTCache() && contentLength > 0 && contentLength < (Response.CRAWLER_MAX_SIZE_TO_CACHE) && !url.isLocal()) { byte[] content = null; try { content = HTTPClient.getByteArray(client.getHttpResponse().getEntity(), maxFileSize); Cache.store(url, responseHeader, content); } catch (final IOException e) { this.log.warn("cannot write " + url + " to Cache (3): " + e.getMessage(), e); } finally { client.finish(); } contentStream = new ByteArrayInputStream(content); } else { /* * Content length may already be known now : check it before opening a stream */ if (maxFileSize >= 0 && contentLength > maxFileSize) { throw new IOException("Content to download exceed maximum value of " + maxFileSize + " bytes"); } /* * Create a HTTPInputStream delegating to * client.getContentstream(). Close method will ensure client is * properly closed. */ contentStream = new HTTPInputStream(client); /* Anticipated content length may not be already known or incorrect : let's apply now the same eventual content size restriction as when loading in a byte array */ if (maxFileSize >= 0) { contentStream = new StrictLimitInputStream(contentStream, maxFileSize, "Content to download exceed maximum value of " + Formatter.bytesToString(maxFileSize)); } } return new StreamResponse(new Response(request, requestHeader, responseHeader, profile, false, null), contentStream); } else { client.finish(); // if the response has not the right response type then reject file this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile, FailCategory.TEMPORARY_NETWORK_FAILURE, "wrong http status code", statusCode); throw new IOException( "REJECTED WRONG STATUS TYPE '" + statusline + "' for URL '" + requestURLString + "'$"); } }
From source file:net.pms.util.GenericIcons.java
public DLNAThumbnailInputStream getGenericIcon(DLNAResource resource) { ImageFormat imageFormat = ImageFormat.JPEG; if (resource == null) { ImageIO.setUseCache(false); ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/*from w w w . j a v a2 s .c o m*/ ImageIOTools.imageIOWrite(genericUnknownIcon, imageFormat.toString(), out); return DLNAThumbnailInputStream.toThumbnailInputStream(out.toByteArray()); } catch (IOException e) { LOGGER.warn("Unexpected error while generating generic thumbnail for null resource: {}", e.getMessage()); LOGGER.trace("", e); return null; } } IconType iconType = IconType.UNKNOWN; if (resource.getMedia() != null) { if (resource.getMedia().isAudio()) { iconType = IconType.AUDIO; } else if (resource.getMedia().isImage()) { iconType = IconType.IMAGE; } else if (resource.getMedia().isVideo()) { // FFmpeg parses images as video, try to rectify if (resource.getFormat() != null && resource.getFormat().isImage()) { iconType = IconType.IMAGE; } else { iconType = IconType.VIDEO; } } } else if (resource.getFormat() != null) { if (resource.getFormat().isAudio()) { iconType = IconType.AUDIO; } else if (resource.getFormat().isImage()) { iconType = IconType.IMAGE; } else if (resource.getFormat().isVideo()) { iconType = IconType.VIDEO; } } DLNAThumbnail image = null; cacheLock.lock(); try { if (!cache.containsKey(imageFormat)) { cache.put(imageFormat, new HashMap<IconType, Map<String, DLNAThumbnail>>()); } Map<IconType, Map<String, DLNAThumbnail>> typeCache = cache.get(imageFormat); if (!typeCache.containsKey(iconType)) { typeCache.put(iconType, new HashMap<String, DLNAThumbnail>()); } Map<String, DLNAThumbnail> imageCache = typeCache.get(iconType); String label = getLabelFromImageFormat(resource.getMedia()); if (label == null) { label = getLabelFromFormat(resource.getFormat()); } if (label == null) { label = getLabelFromContainer(resource.getMedia()); } if (label != null && label.length() < 5) { label = label.toUpperCase(Locale.ROOT); } else if (label != null && label.toLowerCase(Locale.ROOT).equals(label)) { label = StringUtils.capitalize(label); } if (imageCache.containsKey(label)) { return DLNAThumbnailInputStream.toThumbnailInputStream(imageCache.get(label)); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Creating generic {} thumbnail for {} ({})", iconType.toString().toLowerCase(), label.toUpperCase(), imageFormat); } try { image = addFormatLabelToImage(label, imageFormat, iconType); } catch (IOException e) { LOGGER.warn("Unexpected error while generating generic thumbnail for \"{}\": {}", resource.getName(), e.getMessage()); LOGGER.trace("", e); } imageCache.put(label, image); } finally { cacheLock.unlock(); } return DLNAThumbnailInputStream.toThumbnailInputStream(image); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.java
private Handlers getHandlersOrCreateIt(final String type) { final String typeLC = type.toLowerCase(Locale.ROOT); Handlers handlers = eventHandlers_.get(typeLC); if (handlers == null) { handlers = new Handlers(); eventHandlers_.put(typeLC, handlers); }// w ww . j av a 2 s . c o m return handlers; }
From source file:net.pms.dlna.protocolinfo.MimeType.java
/** * Determines whether this and {@code other} is compatible. That means being * either equal or having {@link #ANY} in {@code type} or {@code subtype} is * such a way that they can describe the same content without taking * parameters into account.//from w ww. j av a 2s . c o m * * @param other the {@link MimeType} to check compatibility against. * @return {@code true} of this and {@code other} is compatible, * {@code false} otherwise. */ public boolean isCompatible(MimeType other) { if (other == null) { return false; } if ((isBlank(type) || ANY.equals(type)) && isBlank(subtype) || (isBlank(other.type) || ANY.equals(other.type)) && isBlank(other.subtype)) { return true; } else if (isBlank(type) || (isBlank(other.type))) { return isBlank(subtype) || isBlank(other.subtype) || ANY.equals(subtype) || ANY.equals(other.subtype) || subtype.toLowerCase(Locale.ROOT).equals(other.subtype.toLowerCase(Locale.ROOT)); } else if (type.toLowerCase(Locale.ROOT).equals(other.type.toLowerCase(Locale.ROOT)) && (isBlank(subtype) || ANY.equals(subtype) || isBlank(other.subtype) || ANY.equals(other.subtype))) { return true; } else if (isBlank(subtype) || isBlank(other.subtype)) { return false; } else { return type.toLowerCase(Locale.ROOT).equals(other.type.toLowerCase(Locale.ROOT)) && subtype.toLowerCase(Locale.ROOT).equals(other.subtype.toLowerCase(Locale.ROOT)); } }
From source file:com.digitalpebble.stormcrawler.protocol.httpclient.HttpProtocol.java
@Override public ProtocolResponse handleResponse(HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); Metadata metadata = new Metadata(); HeaderIterator iter = response.headerIterator(); while (iter.hasNext()) { Header header = iter.nextHeader(); metadata.addValue(header.getName().toLowerCase(Locale.ROOT), header.getValue()); }// ww w.jav a2s.co m MutableBoolean trimmed = new MutableBoolean(); byte[] bytes = HttpProtocol.toByteArray(response.getEntity(), maxContent, trimmed); if (trimmed.booleanValue()) { metadata.setValue("http.trimmed", "true"); LOG.warn("HTTP content trimmed to {}", bytes.length); } return new ProtocolResponse(bytes, status, metadata); }
From source file:com.puppycrawl.tools.checkstyle.internal.AllChecksTest.java
@Test public void testAllChecksAreReferencedInConfigFile() throws Exception { final Set<String> checksReferencedInConfig = CheckUtil.getConfigCheckStyleChecks(); final Set<String> checksNames = getSimpleNames(CheckUtil.getCheckstyleChecks()); for (String check : checksNames) { if (!checksReferencedInConfig.contains(check)) { final String errorMessage = String.format(Locale.ROOT, "%s is not referenced in checkstyle_checks.xml", check); Assert.fail(errorMessage);/*from w w w .j a va2 s. co m*/ } } }
From source file:com.digitalpebble.storm.crawler.protocol.httpclient.HttpProtocol.java
@Override public ProtocolResponse handleResponse(HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); Metadata metadata = new Metadata(); HeaderIterator iter = response.headerIterator(); while (iter.hasNext()) { Header header = iter.nextHeader(); metadata.addValue(header.getName().toLowerCase(Locale.ROOT), header.getValue()); }/* ww w .j ava2 s . co m*/ // TODO find a way of limiting by maxContent byte[] bytes = EntityUtils.toByteArray(response.getEntity()); return new ProtocolResponse(bytes, status, metadata); }