本文整理匯總了Java中org.springframework.util.FileCopyUtils.copyToByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Java FileCopyUtils.copyToByteArray方法的具體用法?Java FileCopyUtils.copyToByteArray怎麽用?Java FileCopyUtils.copyToByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.FileCopyUtils
的用法示例。
在下文中一共展示了FileCopyUtils.copyToByteArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: jwtTokenEnhancer
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
Resource resource = new ClassPathResource("public.cert");
String publicKey = null;
try {
publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
} catch (IOException e) {
throw new RuntimeException(e);
}
converter.setVerifierKey(publicKey);
return converter;
}
示例2: doLoadClass
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private Class<?> doLoadClass(String name) throws ClassNotFoundException {
String internalName = StringUtils.replace(name, ".", "/") + ".class";
InputStream is = this.enclosingClassLoader.getResourceAsStream(internalName);
if (is == null) {
throw new ClassNotFoundException(name);
}
try {
byte[] bytes = FileCopyUtils.copyToByteArray(is);
bytes = applyTransformers(name, bytes);
Class<?> cls = defineClass(name, bytes, 0, bytes.length);
// Additional check for defining the package, if not defined yet.
if (cls.getPackage() == null) {
int packageSeparator = name.lastIndexOf('.');
if (packageSeparator != -1) {
String packageName = name.substring(0, packageSeparator);
definePackage(packageName, null, null, null, null, null, null, null);
}
}
this.classCache.put(name, cls);
return cls;
}
catch (IOException ex) {
throw new ClassNotFoundException("Cannot load resource for class [" + name + "]", ex);
}
}
示例3: testGetContentBinary_01
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
public void testGetContentBinary_01() throws Exception
{
// To URL
String url = SpoofedTextContentReader.createContentUrl(Locale.ENGLISH, 12345L, 56L, "harry");
// To Reader
ContentReader reader = new SpoofedTextContentReader(url);
InputStream is = reader.getContentInputStream();
try
{
byte[] bytes = FileCopyUtils.copyToByteArray(is);
assertEquals(56L, bytes.length);
}
finally
{
is.close();
}
// Compare readers
ContentReader copyOne = reader.getReader();
ContentReader copyTwo = reader.getReader();
// Get exactly the same binaries
assertTrue(AbstractContentReader.compareContentReaders(copyOne, copyTwo));
}
示例4: getStringsFromLastExists
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Converts content of last existing file in files to string array
*
* @throws IOException
*/
public static String[] getStringsFromLastExists(String delimiter, File... files) throws IOException {
String[] ret = new String[0];
for (File f : files) {
if (!f.exists())
continue;
String str = new String(FileCopyUtils.copyToByteArray(f), "UTF-8");
ret = StringUtils.tokenizeToStringArray(str, delimiter);
}
return ret;
}
示例5: doGetPrintSecrets
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@RequestMapping(value = "/admin/printSecrets", method = RequestMethod.GET)
public String doGetPrintSecrets(@CookieValue(value = "auth", defaultValue = "notset") String auth, HttpServletResponse response, HttpServletRequest request) throws Exception {
if (request.getSession().getAttribute("auth") == null) {
return fail;
}
String authToken = request.getSession().getAttribute("auth").toString();
if(!isAdmin(authToken)) {
return fail;
}
ClassPathResource cpr = new ClassPathResource("static/calculations.csv");
try {
byte[] bdata = FileCopyUtils.copyToByteArray(cpr.getInputStream());
response.getOutputStream().println(new String(bdata, StandardCharsets.UTF_8));
return null;
} catch (IOException ex) {
ex.printStackTrace();
// redirect to /
return fail;
}
}
示例6: xmlContent
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private Condition<File> xmlContent(URL expected) {
return new Condition<File>("XML Content") {
@Override
public boolean matches(File actual) {
Diff diff = DiffBuilder.compare(Input.from(expected))
.withTest(Input.from(actual)).checkForSimilar().ignoreWhitespace()
.build();
if (diff.hasDifferences()) {
try {
String content = new String(
FileCopyUtils.copyToByteArray(actual));
throw new AssertionError(diff.toString() + "\n" + content);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
return true;
}
};
}
示例7: jwtTokenEnhancer
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Bean
protected JwtAccessTokenConverter jwtTokenEnhancer() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
Resource resource = new ClassPathResource("public.cert");
String publicKey = null;
try {
publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
} catch (IOException e) {
throw new RuntimeException(e);
}
converter.setVerifierKey(publicKey);
return converter;
}
示例8: WebSphereClassPreDefinePlugin
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Create a new {@link WebSphereClassPreDefinePlugin}.
* @param transformer the {@link ClassFileTransformer} to be adapted
* (must not be {@code null})
*/
public WebSphereClassPreDefinePlugin(ClassFileTransformer transformer) {
this.transformer = transformer;
ClassLoader classLoader = transformer.getClass().getClassLoader();
// first force the full class loading of the weaver by invoking transformation on a dummy class
try {
String dummyClass = Dummy.class.getName().replace('.', '/');
byte[] bytes = FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream(dummyClass + ".class"));
transformer.transform(classLoader, dummyClass, null, null, bytes);
}
catch (Throwable ex) {
throw new IllegalArgumentException("Cannot load transformer", ex);
}
}
示例9: getResponseBody
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private byte[] getResponseBody(ClientHttpResponse response) {
try {
InputStream responseBody = response.getBody();
if (responseBody != null) {
return FileCopyUtils.copyToByteArray(responseBody);
}
}
catch (IOException ex) {
// ignore
}
return new byte[0];
}
示例10: jwkSetLoader
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Bean
public JwkSetLoader jwkSetLoader() {
return () -> {
try {
Resource jwkSetResource = this.resourceLoader.getResource(JWK_SET_LOCATION);
String jwkSetJson = new String(FileCopyUtils.copyToByteArray(jwkSetResource.getInputStream()));
return JWKSet.parse(jwkSetJson);
}
catch (IOException | ParseException e) {
throw new RuntimeException(e);
}
};
}
示例11: index
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Handler for / loads the index.tpl
* @param httpResponse
* @param request
* @return
* @throws IOException
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(HttpServletResponse httpResponse, WebRequest request) throws IOException {
ClassPathResource cpr = new ClassPathResource("static/index.html");
String ret = "";
try {
byte[] bdata = FileCopyUtils.copyToByteArray(cpr.getInputStream());
ret= new String(bdata, StandardCharsets.UTF_8);
} catch (IOException e) {
//LOG.warn("IOException", e);
}
return ret;
}
示例12: ContentData
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
public ContentData(ContentStream cs) throws IOException
{
length = cs.getLength();
mimeType = cs.getMimeType();
fileName = cs.getFileName();
bytes = FileCopyUtils.copyToByteArray(cs.getStream());
}
示例13: transformText
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
protected Resource transformText(String fileName, Resource resource) throws IOException {
if (injectableTextFiles.stream()
.noneMatch(p -> pathMatcher.match(p, fileName))) {
log.trace("{} not in injectable-files, skipping", fileName);
return resource;
} else {
log.trace("transforming {}", fileName);
}
final byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
final String content = new String(bytes, DEFAULT_CHARSET);
final StringBuffer transformed = new StringBuffer();
final Matcher m = TEXT_REPLACE_PATTERN.matcher(content);
while (m.find()) {
final String match = m.group(),
key = m.group(1),
fallback = StringUtils.defaultString(m.group(2), match);
if (log.isTraceEnabled()) {
final String replace = environment.getProperty(key);
if (replace == null) {
if (m.group(2) == null) {
log.trace("{} -> '{}' (property not found, no fallback)", match, fallback);
} else {
log.trace("{} -> '{}' (fallback)", match, fallback);
}
} else {
log.trace("{} -> '{}' (env '{}')", match, replace, key);
}
}
m.appendReplacement(transformed, Matcher.quoteReplacement(environment.getProperty(key, fallback)));
}
m.appendTail(transformed);
return new TransformedResource(resource, transformed.toString().getBytes(DEFAULT_CHARSET));
}
示例14: getResponseBody
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
protected byte[] getResponseBody(ClientHttpResponse response) {
try {
InputStream responseBody = response.getBody();
if (responseBody != null) {
return FileCopyUtils.copyToByteArray(responseBody);
}
} catch (IOException ex) {
// ignore
}
return new byte[0];
}
示例15: getBytes
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Override
public byte[] getBytes() throws IOException {
return FileCopyUtils.copyToByteArray(this.part.getInputStream());
}