Java Code Examples for java.util.Locale#ENGLISH

The following examples show how to use java.util.Locale#ENGLISH . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void transferSucceeded(TransferEvent event) {
    transferCompleted(event);

    TransferResource resource = event.getResource();
    long contentLength = event.getTransferredBytes();
    if (contentLength >= 0) {
        String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
        String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";

        String throughput = "";
        long duration = System.currentTimeMillis() - resource.getTransferStartTime();
        if (duration > 0) {
            DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
            double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
            throughput = " at " + format.format(kbPerSec) + " KB/sec";
        }

        log.debug(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput
                + ")");
    }
}
 
Example 2
@Override
public void readMediaEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
    throws ODataApplicationException, ODataLibraryException {
  
  final UriResource firstResoucePart = uriInfo.getUriResourceParts().get(0);
  if(firstResoucePart instanceof UriResourceEntitySet) {
    final EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
    final UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) firstResoucePart;
    
    final Entity entity = storage.readEntityData(edmEntitySet, uriResourceEntitySet.getKeyPredicates());
    if(entity == null) {
      throw new ODataApplicationException("Entity not found", HttpStatusCode.NOT_FOUND.getStatusCode(), 
          Locale.ENGLISH);
    }

    final byte[] mediaContent = storage.readMedia(entity);
    final InputStream responseContent = odata.createFixedFormatSerializer().binary(mediaContent);
    
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setContent(responseContent);
    response.setHeader(HttpHeader.CONTENT_TYPE, entity.getMediaContentType());
  } else {
    throw new ODataApplicationException("Not implemented", HttpStatusCode.BAD_REQUEST.getStatusCode(), 
        Locale.ENGLISH);
  }
}
 
Example 3
Source Project: micro-integrator   File: ODataAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void createEntity(DataRequest request, Entity entity, EntityResponse response)
        throws ODataApplicationException {
    EdmEntitySet edmEntitySet = request.getEntitySet();
    String baseURL = request.getODataRequest().getRawBaseUri();
    try {
        Entity created = createEntityInTable(edmEntitySet.getEntityType(), entity);
        entity.setId(new URI(ODataUtils.buildLocation(baseURL, created, edmEntitySet.getName(),
                                                      edmEntitySet.getEntityType())));
        response.writeCreatedEntity(edmEntitySet, created);
    } catch (ODataServiceFault | SerializerException | URISyntaxException | EdmPrimitiveTypeException e) {
        response.writeNotModified();
        String error = "Error occurred while creating entity. :" + e.getMessage();
        throw new ODataApplicationException(error, 500, Locale.ENGLISH);
    }
}
 
Example 4
@Test
public void resolveViewNameAcceptHeaderSortByQuality() throws Exception {
	request.addHeader("Accept", "text/plain;q=0.5, application/json");

	viewResolver.setContentNegotiationManager(new ContentNegotiationManager(new HeaderContentNegotiationStrategy()));

	ViewResolver htmlViewResolver = mock(ViewResolver.class);
	ViewResolver jsonViewResolver = mock(ViewResolver.class);
	viewResolver.setViewResolvers(Arrays.asList(htmlViewResolver, jsonViewResolver));

	View htmlView = mock(View.class, "text_html");
	View jsonViewMock = mock(View.class, "application_json");

	String viewName = "view";
	Locale locale = Locale.ENGLISH;

	given(htmlViewResolver.resolveViewName(viewName, locale)).willReturn(htmlView);
	given(jsonViewResolver.resolveViewName(viewName, locale)).willReturn(jsonViewMock);
	given(htmlView.getContentType()).willReturn("text/html");
	given(jsonViewMock.getContentType()).willReturn("application/json");

	View result = viewResolver.resolveViewName(viewName, locale);
	assertSame("Invalid view", jsonViewMock, result);
}
 
Example 5
Source Project: msf4j   File: HttpHeadersImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Date getDate() {
    String value = nettyHttpHeaders.get(HttpHeaders.DATE);
    if (value == null || value.isEmpty()) {
        return null;
    }
    // Preferred date format in internet standard is Sun, 06 Nov 1994 08:49:37 GMT
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN, Locale.ENGLISH);
    //All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT)
    dateFormat.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
    try {
        return dateFormat.parse(value);
    } catch (ParseException e) {
        log.error("Error while parsing the Date value. Hence return null", e);
        return null;
    }
}
 
Example 6
@Test
public void testPrintfWithLocale() {
  Locale locale = Locale.ENGLISH;
  String formatString = "Build target [%s] does not exist.";
  String greeter = "//foo:bar";
  PrintStream delegate =
      new PrintStream(new ByteArrayOutputStream()) {
        @Override
        public PrintStream printf(Locale l, String format, Object... args) {
          assertEquals(locale, l);
          assertEquals(format, formatString);
          assertEquals(args[0], greeter);
          return this;
        }
      };

  DirtyPrintStreamDecorator dirtyPrintStream = new DirtyPrintStreamDecorator(delegate);
  PrintStream valueToChain = dirtyPrintStream.printf(locale, formatString, greeter);

  assertEquals(dirtyPrintStream, valueToChain);
  assertTrue(dirtyPrintStream.isDirty());
}
 
Example 7
Source Project: Bytecoder   File: Finished.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
            "\"Finished\": '{'\n" +
            "  \"verify data\": '{'\n" +
            "{0}\n" +
            "  '}'" +
            "'}'",
            Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
            Utilities.indent(hexEncoder.encode(verifyData), "    "),
        };
    return messageFormat.format(messageFields);
}
 
Example 8
@Override
public String toString() {
    MessageFormat messageFormat = new MessageFormat(
        "\"RSA ServerKeyExchange\": '{'\n" +
        "  \"parameters\": '{'\n" +
        "    \"rsa_modulus\": '{'\n" +
        "{0}\n" +
        "    '}',\n" +
        "    \"rsa_exponent\": '{'\n" +
        "{1}\n" +
        "    '}'\n" +
        "  '}',\n" +
        "  \"digital signature\":  '{'\n" +
        "    \"signature\": '{'\n" +
        "{2}\n" +
        "    '}',\n" +
        "  '}'\n" +
        "'}'",
        Locale.ENGLISH);

    HexDumpEncoder hexEncoder = new HexDumpEncoder();
    Object[] messageFields = {
        Utilities.indent(
                hexEncoder.encodeBuffer(modulus), "      "),
        Utilities.indent(
                hexEncoder.encodeBuffer(exponent), "      "),
        Utilities.indent(
                hexEncoder.encodeBuffer(paramsSignature), "      ")
    };
    return messageFormat.format(messageFields);
}
 
Example 9
@BeforeMethod
public void setUp() {
    buf = new StringBuilder();
    builder = new DateTimeFormatterBuilder();
    dta = ZonedDateTime.of(LocalDateTime.of(2011, 6, 30, 12, 30, 40, 0), ZoneId.of("Europe/Paris"));
    locale = Locale.ENGLISH;
    decimalStyle = DecimalStyle.STANDARD;
}
 
Example 10
Source Project: blessed-android   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    TemperatureMeasurement measurement = (TemperatureMeasurement) intent.getSerializableExtra("Temperature");
    if (measurement == null) return;

    DateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH);
    String formattedTimestamp = df.format(measurement.timestamp);
    measurementValue.setText(String.format(Locale.ENGLISH, "%.1f %s (%s)\n%s", measurement.temperatureValue, measurement.unit == TemperatureUnit.Celsius ? "celcius" : "fahrenheit", measurement.type, formattedTimestamp));
}
 
Example 11
Source Project: yuzhouwan   File: GroupTry.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDateFormat2() {
    String str = "1 17:07:42:807 2016";
    SimpleDateFormat sdf = new SimpleDateFormat("d HH:mm:ss:SSS yyyy", Locale.ENGLISH);
    try {
        System.out.println(sdf.parse(str));
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
@Test
public void resolveViewNameFilenameDefaultView() throws Exception {
	request.setRequestURI("/test.json");

	Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
	PathExtensionContentNegotiationStrategy pathStrategy = new PathExtensionContentNegotiationStrategy(mapping);
	viewResolver.setContentNegotiationManager(new ContentNegotiationManager(pathStrategy));

	ViewResolver viewResolverMock1 = mock(ViewResolver.class);
	ViewResolver viewResolverMock2 = mock(ViewResolver.class);
	viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));

	View viewMock1 = mock(View.class, "application_xml");
	View viewMock2 = mock(View.class, "text_html");
	View viewMock3 = mock(View.class, "application_json");

	List<View> defaultViews = new ArrayList<View>();
	defaultViews.add(viewMock3);
	viewResolver.setDefaultViews(defaultViews);

	viewResolver.afterPropertiesSet();

	String viewName = "view";
	Locale locale = Locale.ENGLISH;

	given(viewResolverMock1.resolveViewName(viewName, locale)).willReturn(viewMock1);
	given(viewResolverMock1.resolveViewName(viewName + ".json", locale)).willReturn(null);
	given(viewResolverMock2.resolveViewName(viewName, locale)).willReturn(viewMock2);
	given(viewResolverMock2.resolveViewName(viewName + ".json", locale)).willReturn(null);
	given(viewMock1.getContentType()).willReturn("application/xml");
	given(viewMock2.getContentType()).willReturn("text/html;charset=ISO-8859-1");
	given(viewMock3.getContentType()).willReturn("application/json");

	View result = viewResolver.resolveViewName(viewName, locale);
	assertSame("Invalid view", viewMock3, result);
}
 
Example 13
/**
 * 获取选择的语言设置
 *
 * @param context
 * @return
 */
public static Locale getSetLanguageLocale(Context context) {

    switch (SPUtil.getInstance(context).getSelectLanguage()) {
        case 0:
            return getSystemLocale(context);
        case 1:
            return Locale.CHINA;
        case 2:
        default:
            return Locale.ENGLISH;
    }
}
 
Example 14
@Override
public String getFormattedValue(float value, AxisBase axis) {
    if (value >= labels.size()) {
        return "";
    }
    DateFormat df = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(Long.parseLong(labels.get((int) value)));
    return (df.format(cal.getTime()));
}
 
Example 15
private static DateFormat buildDateFormat() {
	DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
	// For dates without a time, for purposes of interacting with Android,
	// the resulting timestamp
	// needs to be midnight of that day in GMT. See:
	// http://code.google.com/p/android/issues/detail?id=8330
	format.setTimeZone(TimeZone.getTimeZone("GMT"));
	return format;
}
 
Example 16
Source Project: conference-app   File: MainAdapter.java    License: Apache License 2.0 4 votes vote down vote up
public MainAdapter(Context context, List<Conference> objects) {
    mData = objects;
    mContext = context.getApplicationContext();
    simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
    simpleDateFormat2 = new SimpleDateFormat(" - HH:mm", Locale.ENGLISH);
}
 
Example 17
@Before
public void setUp() throws Exception {


    dateParser = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
    dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);

    dateAmPm1 = dateTimeParser.parse("February 3, 2002 01:10:00.000");
    dateAmPm2 = dateTimeParser.parse("February 3, 2002 11:10:00.000");
    dateAmPm3 = dateTimeParser.parse("February 3, 2002 13:10:00.000");
    dateAmPm4 = dateTimeParser.parse("February 3, 2002 19:10:00.000");
    date0 = dateTimeParser.parse("February 3, 2002 12:34:56.789");
    date1 = dateTimeParser.parse("February 12, 2002 12:34:56.789");
    date2 = dateTimeParser.parse("November 18, 2001 1:23:11.321");
    defaultZone = TimeZone.getDefault();
    zone = TimeZone.getTimeZone("MET");
    TimeZone.setDefault(zone);
    dateTimeParser.setTimeZone(zone);
    date3 = dateTimeParser.parse("March 30, 2003 05:30:45.000");
    date4 = dateTimeParser.parse("March 30, 2003 01:10:00.000");
    date5 = dateTimeParser.parse("March 30, 2003 01:40:00.000");
    date6 = dateTimeParser.parse("March 30, 2003 02:10:00.000");
    date7 = dateTimeParser.parse("March 30, 2003 02:40:00.000");
    date8 = dateTimeParser.parse("October 26, 2003 05:30:45.000");
    dateTimeParser.setTimeZone(defaultZone);
    TimeZone.setDefault(defaultZone);
    calAmPm1 = Calendar.getInstance();
    calAmPm1.setTime(dateAmPm1);
    calAmPm2 = Calendar.getInstance();
    calAmPm2.setTime(dateAmPm2);
    calAmPm3 = Calendar.getInstance();
    calAmPm3.setTime(dateAmPm3);
    calAmPm4 = Calendar.getInstance();
    calAmPm4.setTime(dateAmPm4);
    cal1 = Calendar.getInstance();
    cal1.setTime(date1);
    cal2 = Calendar.getInstance();
    cal2.setTime(date2);
    TimeZone.setDefault(zone);
    cal3 = Calendar.getInstance();
    cal3.setTime(date3);
    cal4 = Calendar.getInstance();
    cal4.setTime(date4);
    cal5 = Calendar.getInstance();
    cal5.setTime(date5);
    cal6 = Calendar.getInstance();
    cal6.setTime(date6);
    cal7 = Calendar.getInstance();
    cal7.setTime(date7);
    cal8 = Calendar.getInstance();
    cal8.setTime(date8);
    TimeZone.setDefault(defaultZone);
}
 
Example 18
@Override
protected DateFormat initialValue() {
	return new SimpleDateFormat(CustomFilters.DATE_FORMAT_STRING, Locale.ENGLISH);
}
 
Example 19
private Locale getLocale(String localeName) {
    String language, country;
    int index;

    index = localeName.indexOf('_');
    if (index == -1) {
        //
        // Special case the builtin JDK languages
        //
        if (localeName.equals("de"))
            return Locale.GERMAN;
        if (localeName.equals("en"))
            return Locale.ENGLISH;
        if (localeName.equals("fr"))
            return Locale.FRENCH;
        if (localeName.equals("it"))
            return Locale.ITALIAN;
        if (localeName.equals("ja"))
            return Locale.JAPANESE;
        if (localeName.equals("ko"))
            return Locale.KOREAN;
        if (localeName.equals("zh"))
            return Locale.CHINESE;

        language = localeName;
        country = "";
    } else {
        if (localeName.equals("zh_CN"))
            return Locale.SIMPLIFIED_CHINESE;
        if (localeName.equals("zh_TW"))
            return Locale.TRADITIONAL_CHINESE;

        //
        // JDK also has constants for countries:  en_GB, en_US, en_CA,
        // fr_FR, fr_CA, de_DE, ja_JP, ko_KR.  We don't use those.
        //
        language = localeName.substring(0, index);
        country = localeName.substring(index + 1);
    }

    return new Locale(language, country);
}
 
Example 20
Source Project: DavidWebb   File: WebbUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Creates a new instance of a <code>DateFormat</code> for RFC1123 compliant dates.
 * <br>
 * Should be stored for later use but be aware that this DateFormat is not Thread-safe!
 * <br>
 * If you have to deal with dates in this format with JavaScript, it's easy, because the JavaScript
 * Date object has a constructor for strings formatted this way.
 * @return a new instance
 */
public static DateFormat getRfc1123DateFormat() {
    DateFormat format = new SimpleDateFormat(
            "EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
    format.setLenient(false);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format;
}