本文整理匯總了Java中org.springframework.util.FileCopyUtils.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java FileCopyUtils.copy方法的具體用法?Java FileCopyUtils.copy怎麽用?Java FileCopyUtils.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.FileCopyUtils
的用法示例。
在下文中一共展示了FileCopyUtils.copy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeInternal
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String headerName = entry.getKey();
for (String headerValue : entry.getValue()) {
this.connection.addRequestProperty(headerName, headerValue);
}
}
if (this.connection.getDoOutput() && this.outputStreaming) {
this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
}
this.connection.connect();
if (this.connection.getDoOutput()) {
FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
}
return new SimpleClientHttpResponse(this.connection);
}
示例2: setUp
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Pre-load some fake images
*
* @return Spring Boot {@link CommandLineRunner} automatically run after app context is loaded.
*/
@Bean
CommandLineRunner setUp() throws IOException {
return (args) -> {
FileSystemUtils.deleteRecursively(new File(UPLOAD_ROOT));
Files.createDirectory(Paths.get(UPLOAD_ROOT));
FileCopyUtils.copy("Test file",
new FileWriter(UPLOAD_ROOT +
"/learning-spring-boot-cover.jpg"));
FileCopyUtils.copy("Test file2",
new FileWriter(UPLOAD_ROOT +
"/learning-spring-boot-2nd-edition-cover.jpg"));
FileCopyUtils.copy("Test file3",
new FileWriter(UPLOAD_ROOT + "/bazinga.png"));
};
}
示例3: setBlobAsBinaryStream
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Override
public void setBlobAsBinaryStream(
PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength)
throws SQLException {
Blob blob = ps.getConnection().createBlob();
try {
FileCopyUtils.copy(binaryStream, blob.setBinaryStream(1));
}
catch (IOException ex) {
throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
}
this.temporaryBlobs.add(blob);
ps.setBlob(paramIndex, blob);
if (logger.isDebugEnabled()) {
logger.debug(binaryStream != null ?
"Copied binary stream into temporary BLOB with length " + contentLength :
"Set BLOB to null");
}
}
示例4: handle
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Processes the incoming Burlap request and creates a Burlap response.
*/
@Override
public void handle(HttpExchange exchange) throws IOException {
if (!"POST".equals(exchange.getRequestMethod())) {
exchange.getResponseHeaders().set("Allow", "POST");
exchange.sendResponseHeaders(405, -1);
return;
}
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
try {
invoke(exchange.getRequestBody(), output);
}
catch (Throwable ex) {
exchange.sendResponseHeaders(500, -1);
logger.error("Burlap skeleton invocation failed", ex);
}
exchange.sendResponseHeaders(200, output.size());
FileCopyUtils.copy(output.toByteArray(), exchange.getResponseBody());
}
示例5: shouldPackOnlyMissingResources
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
@Test
public void shouldPackOnlyMissingResources() throws Exception {
ZipFile zipFile = new ZipFile(SampleProjects.springTravel());
try {
ApplicationArchive archive = new ZipApplicationArchive(zipFile);
CloudResources allResources = new CloudResources(archive);
List<CloudResource> resources = new ArrayList<CloudResource>(allResources.asList());
resources.remove(0);
CloudResources knownRemoteResources = new CloudResources(resources);
UploadApplicationPayload payload = new UploadApplicationPayload(archive, knownRemoteResources);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
FileCopyUtils.copy(payload.getInputStream(), bos);
assertThat(payload.getArchive(), is(archive));
assertThat(payload.getTotalUncompressedSize(), is(93));
assertThat(bos.toByteArray().length, is(2451));
} finally {
zipFile.close();
}
}
示例6: getFile
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private TFile getFile(String extension, String location)
{
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
assertNotNull(is);
OutputStream os;
try
{
os = new FileOutputStream(file);
FileCopyUtils.copy(is, os);
}
catch (IOException error)
{
error.printStackTrace();
}
return new TFile(file);
}
示例7: handle
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Processes the incoming Hessian request and creates a Hessian response.
*/
@Override
public void handle(HttpExchange exchange) throws IOException {
if (!"POST".equals(exchange.getRequestMethod())) {
exchange.getResponseHeaders().set("Allow", "POST");
exchange.sendResponseHeaders(405, -1);
return;
}
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
try {
invoke(exchange.getRequestBody(), output);
}
catch (Throwable ex) {
exchange.sendResponseHeaders(500, -1);
logger.error("Hessian skeleton invocation failed", ex);
return;
}
exchange.getResponseHeaders().set("Content-Type", CONTENT_TYPE_HESSIAN);
exchange.sendResponseHeaders(200, output.size());
FileCopyUtils.copy(output.toByteArray(), exchange.getResponseBody());
}
示例8: setUp
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Pre-load some test images
*
* @return Spring Boot {@link CommandLineRunner} automatically
* run after app context is loaded.
*/
@Bean
CommandLineRunner setUp() throws IOException {
return (args) -> {
FileSystemUtils.deleteRecursively(new File(UPLOAD_ROOT));
Files.createDirectory(Paths.get(UPLOAD_ROOT));
FileCopyUtils.copy("Test file",
new FileWriter(UPLOAD_ROOT +
"/learning-spring-boot-cover.jpg"));
FileCopyUtils.copy("Test file2",
new FileWriter(UPLOAD_ROOT +
"/learning-spring-boot-2nd-edition-cover.jpg"));
FileCopyUtils.copy("Test file3",
new FileWriter(UPLOAD_ROOT + "/bazinga.png"));
};
}
示例9: getContent
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
public String getContent()
throws IOException
{
// ensure we only try to read the content once - as this method may be called several times
// but the inputstream can only be processed a single time
if (this.content == null)
{
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
FileCopyUtils.copy(stream, os); // both streams are closed
byte[] bytes = os.toByteArray();
// get the encoding for the string
String encoding = getEncoding();
// create the string from the byte[] using encoding if necessary
this.content = (encoding == null) ? new String(bytes) : new String(bytes, encoding);
}
return this.content;
}
示例10: storeFile
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private StoreEntity storeFile(File file, String mediaId, Resource resource) throws IOException {
file.createNewFile();
file.setLastModified(0l);
FileCopyUtils.copy(resource.getInputStream(), new FileOutputStream(file));
StoreEntity storeEntity = StoreEntity.builder()
.filePath(file.getAbsolutePath())
.createTime(new Date())
.mediaType(null) //有必要的話可以嘗試解析文件名來獲取mediaType,暫時不想做
.mediaId(mediaId)
.lastModifiedTime(new Date(0l))
.build();
return storeEntity;
}
示例11: streamContent
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
/**
* Streams content back to client from a given resource path.
*
* @param req The request
* @param res The response
* @param resourcePath The classpath resource path the content is required for.
* @param attach Indicates whether the content should be streamed as an attachment or not
* @param attachFileName Optional file name to use when attach is <code>true</code>
* @throws IOException
*/
protected void streamContent(WebScriptRequest req,
WebScriptResponse res,
String resourcePath,
boolean attach,
String attachFileName,
Map<String, Object> model) throws IOException
{
if (logger.isDebugEnabled())
logger.debug("Retrieving content from resource path " + resourcePath + " (attach: " + attach + ")");
// get extension of resource
String ext = "";
int extIndex = resourcePath.lastIndexOf('.');
if (extIndex != -1)
{
ext = resourcePath.substring(extIndex);
}
// We need to retrieve the modification date/time from the resource itself.
StringBuilder sb = new StringBuilder("classpath:").append(resourcePath);
final String classpathResource = sb.toString();
long resourceLastModified = resourceLoader.getResource(classpathResource).lastModified();
// create temporary file
File file = TempFileProvider.createTempFile("streamContent-", ext);
InputStream is = resourceLoader.getResource(classpathResource).getInputStream();
OutputStream os = new FileOutputStream(file);
FileCopyUtils.copy(is, os);
// stream the contents of the file, but using the modifiedDate of the original resource.
streamContent(req, res, file, resourceLastModified, attach, attachFileName, model);
}
示例12: testReload
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
public void testReload() throws IOException {
FileCopyUtils.copy(new File(SRC_TEST_RESOURCES_PROPERTIES + EXTERNAL_PROPERTIES), new File(BUILD_TEST_RESOURCES_PROPERTIES + EXTERNAL_PROPERTIES));
ExternalProperties.setPropertiesFilePath(BUILD_TEST_RESOURCES_PROPERTIES + EXTERNAL_PROPERTIES);
final String propertyToAdd = "test.reload=true";
writeNewPropertyToFile(propertyToAdd, BUILD_TEST_RESOURCES_PROPERTIES + EXTERNAL_PROPERTIES);
ExternalProperties.reload();
assertEquals("string property", ExternalProperties.get("string.property"));
assertEquals(Integer.valueOf(5), ExternalProperties.getAsInteger("integer.property"));
assertEquals(Boolean.TRUE, ExternalProperties.getAsBoolean("boolean.property"));
assertEquals(Boolean.TRUE, ExternalProperties.getAsBoolean("test.reload"));
assertNull(ApplicationProperties.get("home team"));
}
示例13: saveBuildInfo
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private void saveBuildInfo(String buildInfo, File buildInfoFile) {
try {
FileCopyUtils.copy(buildInfo, new FileWriter(buildInfoFile));
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
示例14: saveSnapshot
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
public void saveSnapshot(String transferId, InputStream openStream) throws TransferException
{
// Check that this transfer still owns the lock
Lock lock = checkLock(transferId);
try
{
if (log.isDebugEnabled())
{
log.debug("Saving snapshot for transferId =" + transferId);
}
File snapshotFile = new File(getStagingFolder(transferId), SNAPSHOT_FILE_NAME);
try
{
if (snapshotFile.createNewFile())
{
int size = FileCopyUtils.copy(openStream, new BufferedOutputStream(new FileOutputStream(snapshotFile)));
progressMonitor.logComment(transferId, "Received manifest file. Size = " + size);
if (log.isDebugEnabled())
{
log.debug("Saved snapshot for transferId =" + transferId);
}
}
}
catch (Exception ex)
{
throw new TransferException(MSG_ERROR_WHILE_STAGING_SNAPSHOT, ex);
}
}
finally
{
lock.enableLockTimeout();
}
}
示例15: createTemporaryUploadFile
import org.springframework.util.FileCopyUtils; //導入方法依賴的package包/類
private File createTemporaryUploadFile(InputStream inputStream) throws IOException {
File file = File.createTempFile("cfjava", null);
FileOutputStream outputStream = new FileOutputStream(file);
FileCopyUtils.copy(inputStream, outputStream);
outputStream.close();
return file;
}