當前位置: 首頁>>代碼示例>>Java>>正文


Java FileCopyUtils.copyToByteArray方法代碼示例

本文整理匯總了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;
}
 
開發者ID:rhawan,項目名稱:microservices-tcc-alfa,代碼行數:14,代碼來源:JwtConfiguration.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ShadowingClassLoader.java

示例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));
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:23,代碼來源:SpoofedTextContentReaderTest.java

示例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;
}
 
開發者ID:EonTechnology,項目名稱:server,代碼行數:17,代碼來源:ConfigHelper.java

示例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;
  }
}
 
開發者ID:ShiftLeftSecurity,項目名稱:HelloShiftLeft,代碼行數:24,代碼來源:AdminController.java

示例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;
		}

	};
}
 
開發者ID:spring-io,項目名稱:artifactory-resource,代碼行數:24,代碼來源:MavenMetadataGeneratorTests.java

示例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;
}
 
開發者ID:apssouza22,項目名稱:java-microservice,代碼行數:14,代碼來源:JwtConfiguration.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:WebSphereClassPreDefinePlugin.java

示例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];
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:DefaultResponseErrorHandler.java

示例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);
		}
	};
}
 
開發者ID:vpavic,項目名稱:simple-openid-provider,代碼行數:15,代碼來源:OAuth2Configuration.java

示例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;
  }
 
開發者ID:ShiftLeftSecurity,項目名稱:HelloShiftLeft,代碼行數:20,代碼來源:CustomerController.java

示例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());
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:8,代碼來源:ContentData.java

示例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));
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:37,代碼來源:PropertyInjectionTransformer.java

示例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];
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:12,代碼來源:WxResponseErrorHandler.java

示例15: getBytes

import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Override
public byte[] getBytes() throws IOException {
	return FileCopyUtils.copyToByteArray(this.part.getInputStream());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:5,代碼來源:StandardMultipartHttpServletRequest.java


注:本文中的org.springframework.util.FileCopyUtils.copyToByteArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。