Example usage for java.util Locale ROOT

List of usage examples for java.util Locale ROOT

Introduction

In this page you can find the example usage for java.util Locale ROOT.

Prototype

Locale ROOT

To view the source code for java.util Locale ROOT.

Click Source Link

Document

Useful constant for the root locale.

Usage

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java

/**
 * @throws Exception if the test fails// w  ww . j ava 2s. com
 */
@Test
public void testFileInput() throws Exception {
    String path = getClass().getClassLoader().getResource("testfiles/" + "tiny-png.img").toExternalForm();
    testFileInput(path);
    final File file = new File(new URI(path));
    testFileInput(file.getCanonicalPath());

    if (path.startsWith("file:")) {
        path = path.substring("file:".length());
    }
    while (path.startsWith("/")) {
        path = path.substring(1);
    }
    if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) {
        testFileInput(URLDecoder.decode(path.replace('/', '\\'), "UTF-8"));
    }
    testFileInput("file:/" + path);
    testFileInput("file://" + path);
    testFileInput("file:///" + path);
}

From source file:io.crate.PartitionName.java

@Nullable
public void decodeIdent(@Nullable String ident) throws IOException {
    if (ident == null) {
        return;//from www  .  j a  va2 s .c o  m
    }
    byte[] inputBytes = BASE32.decode(ident.toUpperCase(Locale.ROOT));
    BytesStreamInput in = new BytesStreamInput(inputBytes, true);
    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        BytesRef value = StringType.INSTANCE.streamer().readValueFrom(in);
        if (value == null) {
            values.add(null);
        } else {
            values.add(value);
        }
    }
}

From source file:ch.cyberduck.core.ftp.FTPMlsdListResponseReader.java

@Override
public AttributedList<Path> read(final Path directory, final List<String> replies,
        final ListProgressListener listener)
        throws IOException, FTPInvalidListException, ConnectionCanceledException {
    final AttributedList<Path> children = new AttributedList<Path>();
    // At least one entry successfully parsed
    boolean success = false;
    for (String line : replies) {
        final Map<String, Map<String, String>> file = this.parseFacts(line);
        if (null == file) {
            log.error(String.format("Error parsing line %s", line));
            continue;
        }//from  w w w.ja  v a2s .co m
        for (Map.Entry<String, Map<String, String>> f : file.entrySet()) {
            final String name = f.getKey();
            // size       -- Size in octets
            // modify     -- Last modification time
            // create     -- Creation time
            // type       -- Entry type
            // unique     -- Unique id of file/directory
            // perm       -- File permissions, whether read, write, execute is allowed for the login id.
            // lang       -- Language of the file name per IANA [11] registry.
            // media-type -- MIME media-type of file contents per IANA registry.
            // charset    -- Character set per IANA registry (if not UTF-8)
            final Map<String, String> facts = f.getValue();
            if (!facts.containsKey("type")) {
                log.error(String.format("No type fact in line %s", line));
                continue;
            }
            final Path parsed;
            if ("dir".equals(facts.get("type").toLowerCase(Locale.ROOT))) {
                parsed = new Path(directory, PathNormalizer.name(f.getKey()), EnumSet.of(Path.Type.directory));
            } else if ("file".equals(facts.get("type").toLowerCase(Locale.ROOT))) {
                parsed = new Path(directory, PathNormalizer.name(f.getKey()), EnumSet.of(Path.Type.file));
            } else if (facts.get("type").toLowerCase(Locale.ROOT).matches("os\\.unix=slink:.*")) {
                parsed = new Path(directory, PathNormalizer.name(f.getKey()),
                        EnumSet.of(Path.Type.file, Path.Type.symboliclink));
                // Parse symbolic link target in Type=OS.unix=slink:/foobar;Perm=;Unique=keVO1+4G4; foobar
                final String[] type = facts.get("type").split(":");
                if (type.length == 2) {
                    final String target = type[1];
                    if (target.startsWith(String.valueOf(Path.DELIMITER))) {
                        parsed.setSymlinkTarget(new Path(target, EnumSet.of(Path.Type.file)));
                    } else {
                        parsed.setSymlinkTarget(
                                new Path(String.format("%s/%s", directory.getAbsolute(), target),
                                        EnumSet.of(Path.Type.file)));
                    }
                } else {
                    log.warn(String.format("Missing symbolic link target for type %s in line %s",
                            facts.get("type"), line));
                    continue;
                }
            } else {
                log.warn(String.format("Ignored type %s in line %s", facts.get("type"), line));
                continue;
            }
            if (!success) {
                if (parsed.isDirectory() && directory.getName().equals(name)) {
                    log.warn(String.format("Possibly bogus response line %s", line));
                } else {
                    success = true;
                }
            }
            if (name.equals(".") || name.equals("..")) {
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Skip %s", name));
                }
                continue;
            }
            if (facts.containsKey("size")) {
                parsed.attributes().setSize(Long.parseLong(facts.get("size")));
            }
            if (facts.containsKey("unix.uid")) {
                parsed.attributes().setOwner(facts.get("unix.uid"));
            }
            if (facts.containsKey("unix.owner")) {
                parsed.attributes().setOwner(facts.get("unix.owner"));
            }
            if (facts.containsKey("unix.gid")) {
                parsed.attributes().setGroup(facts.get("unix.gid"));
            }
            if (facts.containsKey("unix.group")) {
                parsed.attributes().setGroup(facts.get("unix.group"));
            }
            if (facts.containsKey("unix.mode")) {
                parsed.attributes().setPermission(new Permission(facts.get("unix.mode")));
            } else if (facts.containsKey("perm")) {
                Permission.Action user = Permission.Action.none;
                final String flags = facts.get("perm");
                if (StringUtils.contains(flags, 'r') || StringUtils.contains(flags, 'l')) {
                    // RETR command may be applied to that object
                    // Listing commands, LIST, NLST, and MLSD may be applied
                    user.or(Permission.Action.read);
                }
                if (StringUtils.contains(flags, 'w') || StringUtils.contains(flags, 'm')
                        || StringUtils.contains(flags, 'c')) {
                    user.or(Permission.Action.write);
                }
                if (StringUtils.contains(flags, 'e')) {
                    // CWD command naming the object should succeed
                    user.or(Permission.Action.execute);
                }
                final Permission permission = new Permission(user, Permission.Action.none,
                        Permission.Action.none);
                parsed.attributes().setPermission(permission);
            }
            if (facts.containsKey("modify")) {
                // Time values are always represented in UTC
                parsed.attributes().setModificationDate(this.parseTimestamp(facts.get("modify")));
            }
            if (facts.containsKey("create")) {
                // Time values are always represented in UTC
                parsed.attributes().setCreationDate(this.parseTimestamp(facts.get("create")));
            }
            children.add(parsed);
        }
    }
    if (!success) {
        throw new FTPInvalidListException(children);
    }
    return children;
}

From source file:net.pms.util.FullyPlayedAction.java

/**
 * Converts the {@link String} passed as argument to a
 * {@link FullyPlayedAction}. If the conversion fails, this method returns
 * {@code defaultFullyPlayedAction}.//from  ww  w . j a v  a  2 s  . c  o  m
 *
 * @param sArg the {@link String} to try convert.
 * @param defaultFullyPlayedAction the default value to return if the
 *            conversion fails.
 * @return The corresponding value or {@code defaultFullyPlayedAction} if
 *         not match is found.
 */
public static FullyPlayedAction toFullyPlayedAction(String sArg, FullyPlayedAction defaultFullyPlayedAction) {
    if (StringUtils.isBlank(sArg)) {
        return defaultFullyPlayedAction;
    }
    sArg = sArg.toLowerCase(Locale.ROOT);
    if (sArg.contains("action")) {
        return FullyPlayedAction.NO_ACTION;
    }
    if (sArg.contains("mark")) {
        return FullyPlayedAction.MARK;
    }
    if (sArg.contains("hide")) {
        return FullyPlayedAction.HIDE_VIDEO;
    }
    if (sArg.contains("folder")) {
        return FullyPlayedAction.MOVE_FOLDER;
    }
    if (sArg.contains("trash") || sArg.contains("recycle")) {
        return FullyPlayedAction.MOVE_TRASH;
    }
    return defaultFullyPlayedAction;
}

From source file:com.sindicetech.siren.solr.handler.JsonLoader.java

@Override
public void load(final SolrQueryRequest req, final SolrQueryResponse rsp, final ContentStream stream,
        final UpdateRequestProcessor processor) throws Exception {
    Reader reader = null;/*from  w  w w .  ja  va2s. com*/
    try {
        reader = stream.getReader();
        // keep a copy of the body for the source entry
        // TODO: instead of reading the stream to make a copy, try to create a copy of the json
        // while parsing it in the JsonReader
        String body = IOUtils.toString(reader);

        FieldMappersHandler mappersHandler = new FieldMappersHandler(fieldMappers, req.getCore());
        DocumentBuilder docBuilder = new DocumentBuilder();

        // Add the source field entry
        FieldEntry source = new FieldEntry(SOURCE_FIELDNAME, body);
        docBuilder.add(mappersHandler.map(source));

        // Add the id field initialised with a UUID. It will be overwritten if an id field exist in the JSON document.
        FieldEntry id = new FieldEntry(IdFieldMapper.INPUT_FIELD,
                UUID.randomUUID().toString().toLowerCase(Locale.ROOT));
        docBuilder.add(mappersHandler.map(id));

        JsonParser parser = mapper.getJsonFactory().createJsonParser(new StringReader(body));
        JsonReader jreader = new JsonReader(parser);

        FieldEntry entry;
        while ((entry = jreader.next()) != null) {
            docBuilder.add(mappersHandler.map(entry));
        }

        // the index schema might have changed
        req.updateSchemaToLatest();

        // check that we have seen all the required field mappers
        Set<String> missingRequiredMappers = mappersHandler.getMissingRequiredMappers();
        if (!missingRequiredMappers.isEmpty()) {
            throw new SolrException(BAD_REQUEST,
                    "Document is missing the following required fields: " + missingRequiredMappers);
        }

        // Create and process the Add command
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docBuilder.getSolrInputDocument();
        processor.processAdd(cmd);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:com.puppycrawl.tools.checkstyle.MainTest.java

@Test
public void testWrongArgument() throws Exception {
    exit.expectSystemExitWithStatus(-1);
    exit.checkAssertionAfterwards(new Assertion() {
        @Override/*www  . j ava 2  s .c o m*/
        public void checkAssertion() {
            String usage = String.format(Locale.ROOT, "Unrecognized option: -w%n"
                    + "usage: java com.puppycrawl.tools.checkstyle.Main [options] -c <config.xml>%n"
                    + "            file...%n" + " -c <arg>   Sets the check configuration file to use.%n"
                    + " -f <arg>   Sets the output format. (plain|xml). Defaults to plain%n"
                    + " -o <arg>   Sets the output file. Defaults to stdout%n"
                    + " -p <arg>   Loads the properties file%n"
                    + " -v         Print product version and exit%n");

            assertEquals(usage, systemOut.getLog());
            assertEquals("", systemErr.getLog());
        }
    });
    Main.main("-w");
}

From source file:ch.cyberduck.ui.cocoa.TransferTableDataSource.java

/**
 * @param searchString Filter hostname or file
 *///from   w w  w  .ja va  2s .co  m
public void setFilter(final String searchString) {
    if (StringUtils.isBlank(searchString)) {
        // Revert to the default filter
        this.filter = new NullTransferFilter();
    } else {
        // Setting up a custom filter
        this.filter = new TransferFilter() {
            @Override
            public boolean accept(final Transfer transfer) {
                // Match for path names and hostname
                for (TransferItem root : transfer.getRoots()) {
                    if (root.remote.getName().toLowerCase(Locale.ROOT)
                            .contains(searchString.toLowerCase(Locale.ROOT))) {
                        return true;
                    }
                }
                if (transfer.getHost().getHostname().toLowerCase(Locale.ROOT)
                        .contains(searchString.toLowerCase(Locale.ROOT))) {
                    return true;
                }
                return false;
            }
        };
    }
}

From source file:org.elasticsearch.integration.AbstractPrivilegeTestCase.java

protected void assertAccessIsDenied(String user, String method, String uri, String body,
        Map<String, String> params) throws IOException {
    ResponseException responseException = expectThrows(ResponseException.class,
            () -> getRestClient().performRequest(method, uri, params, entityOrNull(body),
                    new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, UsernamePasswordToken
                            .basicAuthHeaderValue(user, new SecureString("passwd".toCharArray())))));
    StatusLine statusLine = responseException.getResponse().getStatusLine();
    String message = String.format(Locale.ROOT, "%s %s body %s: Expected 403, got %s %s with body %s", method,
            uri, body, statusLine.getStatusCode(), statusLine.getReasonPhrase(),
            EntityUtils.toString(responseException.getResponse().getEntity()));
    assertThat(message, statusLine.getStatusCode(), is(403));
}

From source file:ch.cyberduck.core.importer.TotalCommanderBookmarkCollection.java

@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
    try {/*from   ww  w .  j a  va  2s  .  c  o  m*/
        final BufferedReader in = new BufferedReader(
                new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")));
        try {
            Host current = null;
            String line;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("[")) {
                    if (current != null) {
                        this.add(current);
                    }
                    current = new Host(protocols.forScheme(Scheme.ftp));
                    current.getCredentials()
                            .setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name"));
                    Pattern pattern = Pattern.compile("\\[(.*)\\]");
                    Matcher matcher = pattern.matcher(line);
                    if (matcher.matches()) {
                        current.setNickname(matcher.group(1));
                    }
                } else {
                    if (null == current) {
                        log.warn("Failed to detect start of bookmark");
                        continue;
                    }
                    final Scanner scanner = new Scanner(line);
                    scanner.useDelimiter("=");
                    if (!scanner.hasNext()) {
                        log.warn("Missing key in line:" + line);
                        continue;
                    }
                    final String name = scanner.next().toLowerCase(Locale.ROOT);
                    if (!scanner.hasNext()) {
                        log.warn("Missing value in line:" + line);
                        continue;
                    }
                    final String value = scanner.next();
                    if ("host".equals(name)) {
                        current.setHostname(value);
                    } else if ("directory".equals(name)) {
                        current.setDefaultPath(value);
                    } else if ("username".equals(name)) {
                        current.getCredentials().setUsername(value);
                    } else {
                        log.warn(String.format("Ignore property %s", name));
                    }
                }
            }
            if (current != null) {
                this.add(current);
            }
        } finally {
            IOUtils.closeQuietly(in);
        }
    } catch (IOException e) {
        throw new AccessDeniedException(e.getMessage(), e);
    }
}

From source file:ch.cyberduck.core.importer.WinScpBookmarkCollection.java

@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
    try {/*w w  w .ja  v  a  2  s  .c o  m*/
        final BufferedReader in = new BufferedReader(
                new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")));
        try {
            Host current = null;
            String line;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("[Sessions\\")) {
                    current = new Host(protocols.forScheme(Scheme.sftp));
                    current.getCredentials()
                            .setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name"));
                    Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]");
                    Matcher matcher = pattern.matcher(line);
                    if (matcher.matches()) {
                        current.setNickname(matcher.group(1));
                    }
                } else if (StringUtils.isBlank(line)) {
                    this.add(current);
                    current = null;
                } else {
                    if (null == current) {
                        log.warn("Failed to detect start of bookmark");
                        continue;
                    }
                    Scanner scanner = new Scanner(line);
                    scanner.useDelimiter("=");
                    if (!scanner.hasNext()) {
                        log.warn("Missing key in line:" + line);
                        continue;
                    }
                    String name = scanner.next().toLowerCase(Locale.ROOT);
                    if (!scanner.hasNext()) {
                        log.warn("Missing value in line:" + line);
                        continue;
                    }
                    String value = scanner.next();
                    if ("hostname".equals(name)) {
                        current.setHostname(value);
                    } else if ("username".equals(name)) {
                        current.getCredentials().setUsername(value);
                    } else if ("portnumber".equals(name)) {
                        try {
                            current.setPort(Integer.parseInt(value));
                        } catch (NumberFormatException e) {
                            log.warn("Invalid Port:" + e.getMessage());
                        }
                    } else if ("fsprotocol".equals(name)) {
                        try {
                            switch (Integer.parseInt(value)) {
                            case 0:
                            case 1:
                            case 2:
                                current.setProtocol(protocols.forScheme(Scheme.sftp));
                                break;
                            case 5:
                                current.setProtocol(protocols.forScheme(Scheme.ftp));
                                break;
                            }
                            // Reset port to default
                            current.setPort(-1);
                        } catch (NumberFormatException e) {
                            log.warn("Unknown Protocol:" + e.getMessage());
                        }
                    }
                }
            }
        } finally {
            IOUtils.closeQuietly(in);
        }
    } catch (IOException e) {
        throw new AccessDeniedException(e.getMessage(), e);
    }
}