Example usage for java.util Locale US

List of usage examples for java.util Locale US

Introduction

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

Prototype

Locale US

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

Click Source Link

Document

Useful constant for country.

Usage

From source file:marytts.tools.analysis.CopySynthesis.java

/**
 * @param args/*  ww w .  j a  va  2s .c o  m*/
 */
public static void main(String[] args) throws Exception {
    String wavFilename = null;
    String labFilename = null;
    String pitchFilename = null;
    String textFilename = null;

    String locale = System.getProperty("locale");
    if (locale == null) {
        throw new IllegalArgumentException("No locale given (-Dlocale=...)");
    }

    for (String arg : args) {
        if (arg.endsWith(".txt"))
            textFilename = arg;
        else if (arg.endsWith(".wav"))
            wavFilename = arg;
        else if (arg.endsWith(".ptc"))
            pitchFilename = arg;
        else if (arg.endsWith(".lab"))
            labFilename = arg;
        else
            throw new IllegalArgumentException("Don't know how to treat argument: " + arg);
    }

    // The intonation contour
    double[] contour = null;
    double frameShiftTime = -1;
    if (pitchFilename == null) { // need to create pitch contour from wav file 
        if (wavFilename == null) {
            throw new IllegalArgumentException("Need either a pitch file or a wav file");
        }
        AudioInputStream ais = AudioSystem.getAudioInputStream(new File(wavFilename));
        AudioDoubleDataSource audio = new AudioDoubleDataSource(ais);
        PitchFileHeader params = new PitchFileHeader();
        params.fs = (int) ais.getFormat().getSampleRate();
        F0TrackerAutocorrelationHeuristic tracker = new F0TrackerAutocorrelationHeuristic(params);
        tracker.pitchAnalyze(audio);
        frameShiftTime = tracker.getSkipSizeInSeconds();
        contour = tracker.getF0Contour();
    } else { // have a pitch file -- ignore any wav file
        PitchReaderWriter f0rw = new PitchReaderWriter(pitchFilename);
        if (f0rw.contour == null) {
            throw new NullPointerException("Cannot read f0 contour from " + pitchFilename);
        }
        contour = f0rw.contour;
        frameShiftTime = f0rw.header.skipSizeInSeconds;
    }
    assert contour != null;
    assert frameShiftTime > 0;

    // The ALLOPHONES data and labels
    if (labFilename == null) {
        throw new IllegalArgumentException("No label file given");
    }
    if (textFilename == null) {
        throw new IllegalArgumentException("No text file given");
    }
    MaryTranscriptionAligner aligner = new MaryTranscriptionAligner();
    aligner.SetEnsureInitialBoundary(false);
    String labels = MaryTranscriptionAligner.readLabelFile(aligner.getEntrySeparator(),
            aligner.getEnsureInitialBoundary(), labFilename);
    MaryHttpClient mary = new MaryHttpClient();
    String text = FileUtils.readFileToString(new File(textFilename), "ASCII");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    mary.process(text, "TEXT", "ALLOPHONES", locale, null, null, baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setNamespaceAware(true);
    DocumentBuilder builder = docFactory.newDocumentBuilder();
    Document doc = builder.parse(bais);
    aligner.alignXmlTranscriptions(doc, labels);
    assert doc != null;

    // durations
    double[] endTimes = new LabelfileDoubleDataSource(new File(labFilename)).getAllData();
    assert endTimes.length == labels.split(Pattern.quote(aligner.getEntrySeparator())).length;

    // Now add durations and f0 targets to document
    double prevEnd = 0;
    NodeIterator ni = MaryDomUtils.createNodeIterator(doc, MaryXML.PHONE, MaryXML.BOUNDARY);
    for (int i = 0; i < endTimes.length; i++) {
        Element e = (Element) ni.nextNode();
        if (e == null)
            throw new IllegalStateException("More durations than elements -- this should not happen!");
        double durInSeconds = endTimes[i] - prevEnd;
        int durInMillis = (int) (1000 * durInSeconds);
        if (e.getTagName().equals(MaryXML.PHONE)) {
            e.setAttribute("d", String.valueOf(durInMillis));
            e.setAttribute("end", new Formatter(Locale.US).format("%.3f", endTimes[i]).toString());
            // f0 targets at beginning, mid, and end of phone
            StringBuilder f0String = new StringBuilder();
            double startF0 = getF0(contour, frameShiftTime, prevEnd);
            if (startF0 != 0 && !Double.isNaN(startF0)) {
                f0String.append("(0,").append((int) startF0).append(")");
            }
            double midF0 = getF0(contour, frameShiftTime, prevEnd + 0.5 * durInSeconds);
            if (midF0 != 0 && !Double.isNaN(midF0)) {
                f0String.append("(50,").append((int) midF0).append(")");
            }
            double endF0 = getF0(contour, frameShiftTime, endTimes[i]);
            if (endF0 != 0 && !Double.isNaN(endF0)) {
                f0String.append("(100,").append((int) endF0).append(")");
            }
            if (f0String.length() > 0) {
                e.setAttribute("f0", f0String.toString());
            }
        } else { // boundary
            e.setAttribute("duration", String.valueOf(durInMillis));
        }
        prevEnd = endTimes[i];
    }
    if (ni.nextNode() != null) {
        throw new IllegalStateException("More elements than durations -- this should not happen!");
    }

    // TODO: add pitch values

    String acoustparams = DomUtils.document2String(doc);
    System.out.println("ACOUSTPARAMS:");
    System.out.println(acoustparams);
}

From source file:Main.java

/**
 * Get the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *//*  w ww. j  a  v  a 2s.  c  o m*/
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = Environment.getExternalStorageDirectory();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().toLowerCase(Locale.US).endsWith(".xml")
                        || pathname.getPath().toLowerCase(Locale.US).endsWith(".json"))) {
                    return true;
                }
                return false;
            }
        };

        File[] files = folder.listFiles(filter);

        for (File file : files) {
            result.add(file.getName());
        }
    }

    Collections.sort(result, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            return arg1.compareTo(arg0);
        }
    });

    return result;
}

From source file:Main.java

public static String formatValue(double value) {
    if (value < 0) {
        throw new NumberFormatException("Negative value " + value);
    }/*from   w  w w  .  jav  a 2  s.c o  m*/
    String s = String.format(Locale.US, "%.8f", value);
    while (s.length() > 1 && (s.endsWith("0") || s.endsWith("."))) {
        s = (s.substring(0, s.length() - 1));
    }
    return s;
}

From source file:com.esofthead.mycollab.configuration.LocaleHelper.java

public static Locale toLocale(String language) {
    if (language == null) {
        return Locale.US;
    }/*  ww  w  .j  a v  a  2 s  .c o m*/

    Locale locale = LocaleUtils.toLocale(language);
    return (locale != null) ? locale : SiteConfiguration.getDefaultLocale();
}

From source file:Main.java

/**
 * Parsing the TimeZone of time in milliseconds.
 *
 * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}.
 * @return The number of milliseconds from 1970.1.1.
 * @throws ParseException if an error occurs during parsing.
 *///from  ww w  . j  av a  2  s. c  o m
public static long parseGMTToMillis(String gmtTime) throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US);
    formatter.setTimeZone(GMT_TIME_ZONE);
    Date date = formatter.parse(gmtTime);
    return date.getTime();
}

From source file:Main.java

public static Locale string2locale(String localeString) {
    //        Locale locale = null;
    //        StringTokenizer localeST = new StringTokenizer(localeString, "_");
    //        String language = localeST.nextToken();
    //        String country = "";
    //        String variant = "";
    //        if (localeST.hasMoreTokens()) {
    //            country = localeST.nextToken();
    //            if (localeST.hasMoreTokens()) {
    //                variant = localeST.nextToken();
    //            }
    //        }//w  w w .  ja  v a 2 s.c  o  m
    //        locale = new Locale(language, country, variant);
    return Locale.US;
}

From source file:gov.nih.nci.caarray.web.util.UserComparator.java

/**
 * Extracts last and first name from a string like <code>&lt;a href="..."&gt;last, first&lt;/a&gt;</code>.
 * @param s the html to extrat names from
 * @return UPPER(last), UPPER(first)//from w ww.  j  av a2s. co m
 */
public static String[] getNames(String s) {
    Pattern p = Pattern.compile("[^>]*>\\s*(.*),\\s*(.*)<[^<]*");
    Matcher m = p.matcher(s.toUpperCase(Locale.US));
    m.lookingAt();
    return new String[] { m.group(1).trim(), m.group(2).trim() };
}

From source file:Main.java

public static String enCrypto(String txt, String key) {

    if (txt != null && !"".equals(txt) && !"null".equals(txt)) {

        try {/*from  www .  ja  v  a  2 s.c o m*/

            StringBuffer sb = new StringBuffer();
            DESKeySpec desKeySpec = new DESKeySpec(key.getBytes());
            SecretKeyFactory skeyFactory = null;
            Cipher cipher = null;
            try {
                skeyFactory = SecretKeyFactory.getInstance("DES");
                cipher = Cipher.getInstance("DES");
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            SecretKey deskey = skeyFactory.generateSecret(desKeySpec);
            cipher.init(Cipher.ENCRYPT_MODE, deskey);
            byte[] cipherText = cipher.doFinal(txt.getBytes());
            for (int n = 0; n < cipherText.length; n++) {
                String stmp = (java.lang.Integer.toHexString(cipherText[n] & 0XFF));
                if (stmp.length() == 1) {
                    sb.append("0" + stmp);
                } else {
                    sb.append(stmp);
                }
            }
            return sb.toString().toUpperCase(Locale.US);

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
    return null;
}

From source file:com.mgjg.ProfileManager.attribute.builtin.xmit.XmitAttribute.java

private static String makeRegistryJSON(String serviceName, int typeId, String name, int order) {
    return String.format(Locale.US,
            "{ \"service\" : \"%1$s\", \"id\" : \"%2$d\", \"name\" : \"%3$s\", \"order\" : \"%4$d\"}",
            serviceName, typeId, name, order);
}

From source file:com.spotify.styx.model.Schedule.java

private static WellKnown toWellKnown(String expression) {
    switch (expression.toLowerCase(Locale.US)) {
    case "@hourly":
    case "hourly":
    case "hours":
        return WellKnown.HOURLY;
    case "@daily":
    case "daily":
    case "days":
        return WellKnown.DAILY;
    case "@weekly":
    case "weekly":
    case "weeks":
        return WellKnown.WEEKLY;
    case "@monthly":
    case "monthly":
    case "months":
        return WellKnown.MONTHLY;
    case "@annually":
    case "annually":
    case "@yearly":
    case "yearly":
    case "years":
        return WellKnown.YEARLY;

    default:/*from   w w w. j av  a 2  s .  c o  m*/
        return WellKnown.UNKNOWN;
    }
}