private String contentType(String path) { if (path.endsWith(".png")) return "image/png"; if (path.endsWith(".jpg")) return "image/jpeg"; if (path.endsWith(".jpeg")) return "image/jpeg"; if (path.endsWith(".gif")) return "image/gif"; if (path.endsWith(".html")) return "text/html; charset=utf-8"; if (path.endsWith(".txt")) return "text/plain; charset=utf-8"; return "application/octet-stream"; }
/** * Configure the prefix to use for destinations targeting a specific user. * <p>The default value is "/user/". * @see org.springframework.messaging.simp.user.UserDestinationMessageHandler */ public void setUserDestinationPrefix(String prefix) { Assert.hasText(prefix, "User destination prefix must not be empty"); this.destinationPrefix = (prefix.endsWith("/") ? prefix : prefix + "/"); }
@Override public String addVersion(String path, String version) { if (path.startsWith(".")) { return path; } else if (this.prefix.endsWith("/") || path.startsWith("/")) { return this.prefix + path; } else { return this.prefix + '/' + path; } }
private String padEtagIfNecessary(String etag) { if (!StringUtils.hasLength(etag)) { return etag; } if ((etag.startsWith("\"") || etag.startsWith("W/\"")) && etag.endsWith("\"")) { return etag; } return "\"" + etag + "\""; }
@Override public String toString() { String result = this.builder.toString(); if (result.endsWith("\n")) { result = result.substring(0, result.length() - 1); } return result; }
@Override Optional<String> chop(String str) { if (str.endsWith(suffix)) { return Optional.of(str.substring(0, str.length() - suffix.length())); } else { return Optional.absent(); } } };
private static boolean domainMatch(String urlHost, String domain) { if (urlHost.equals(domain)) { return true; // As in 'example.com' matching 'example.com'. } if (urlHost.endsWith(domain) && urlHost.charAt(urlHost.length() - domain.length() - 1) == '.' && !verifyAsIpAddress(urlHost)) { return true; // As in 'example.com' matching 'www.example.com'. } return false; }
private static boolean pathMatch(HttpUrl url, String path) { String urlPath = url.encodedPath(); if (urlPath.equals(path)) { return true; // As in '/foo' matching '/foo'. } if (urlPath.startsWith(path)) { if (path.endsWith("/")) return true; // As in '/' matching '/foo'. if (urlPath.charAt(path.length()) == '/') return true; // As in '/foo' matching '/foo/bar'. } return false; }
@Override public EntityResponse.Builder<T> eTag(String etag) { if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) { etag = "\"" + etag; } if (!etag.endsWith("\"")) { etag = etag + "\""; } this.headers.setETag(etag); return this; }
public PatternInfo(@Nullable String pattern) { this.pattern = pattern; if (this.pattern != null) { initCounters(); this.catchAllPattern = this.pattern.equals("/**"); this.prefixPattern = !this.catchAllPattern && this.pattern.endsWith("/**"); } if (this.uriVars == 0) { this.length = (this.pattern != null ? this.pattern.length() : 0); } }
/** * Determine whether the given class should be excluded from shadowing. * @param className the name of the class * @return whether the specified class should be shadowed */ private boolean shouldShadow(String className) { return (!className.equals(getClass().getName()) && !className.endsWith("ShadowingClassLoader") && isEligibleForShadowing(className)); }
static ResourceInfo of(String resourceName, ClassLoader loader) { if (resourceName.endsWith(CLASS_FILE_NAME_EXTENSION)) { return new ClassInfo(resourceName, loader); } else { return new ResourceInfo(resourceName, loader); } }
File directoryOf(String baseClassName) throws Exception { File f = MaybeNo2Dot0Since.findSource("Flowable"); if (f == null) { return null; } String parent = f.getParentFile().getAbsolutePath().replace('\\', '/'); if (!parent.endsWith("/")) { parent += "/"; } parent += "internal/operators/" + baseClassName.toLowerCase() + "/"; return new File(parent); }
@Override public Context createSubcontext(String name) { String subcontextName = this.root + name; if (!subcontextName.endsWith("/")) { subcontextName += "/"; } Context subcontext = new SimpleNamingContext(subcontextName, this.boundObjects, this.environment); bind(name, subcontext); return subcontext; }
private void assertToNumberOverflow(Number number, Class<? extends Number> targetClass) { String msg = "Expected exception due to overflow: from=" + number + ", toClass=" + targetClass; try { NumberUtils.convertNumberToTargetClass(number, targetClass); fail(msg); } catch (IllegalArgumentException expected) { assertTrue(msg + ", with \"overflow\" in message but got message=" + expected.getMessage(), expected.getMessage().endsWith("overflow")); } }
@GwtIncompatible // reflection public void testConstants_charset() throws Exception { for (Field field : getConstantFields()) { Optional<Charset> charset = ((MediaType) field.get(null)).charset(); if (field.getName().endsWith("_UTF_8")) { assertThat(charset).hasValue(UTF_8); } else { assertThat(charset).isAbsent(); } } }
@Test public void testBindLocalDateTime() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTime").toString(); assertTrue(value.startsWith("10/31/09")); assertTrue(value.endsWith("12:00 PM")); }
@Test public void testBindLocalDateTimeAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTimeAnnotated", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString(); assertTrue(value.startsWith("Oct 31, 2009")); assertTrue(value.endsWith("12:00:00 PM")); }
@Test public void testBindLocalDateTimeFromJavaUtilCalendar() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTime", new GregorianCalendar(2009, 9, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTime").toString(); assertTrue(value.startsWith("10/31/09")); assertTrue(value.endsWith("12:00 PM")); }
@Test public void connectWebSocketDisabled() throws URISyntaxException { setupInfoRequest(false); this.sockJsClient.doHandshake(handler, URL); assertFalse(this.webSocketTransport.invoked()); assertTrue(this.xhrTransport.invoked()); assertTrue(this.xhrTransport.getRequest().getTransportUrl().toString().endsWith("xhr_streaming")); }