本文整理匯總了Java中org.springframework.util.FileCopyUtils類的典型用法代碼示例。如果您正苦於以下問題:Java FileCopyUtils類的具體用法?Java FileCopyUtils怎麽用?Java FileCopyUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileCopyUtils類屬於org.springframework.util包,在下文中一共展示了FileCopyUtils類的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: 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);
}
}
示例4: setClobAsAsciiStream
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
@Override
public void setClobAsAsciiStream(
PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength)
throws SQLException {
Clob clob = ps.getConnection().createClob();
try {
FileCopyUtils.copy(asciiStream, clob.setAsciiStream(1));
}
catch (IOException ex) {
throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
}
this.temporaryClobs.add(clob);
ps.setClob(paramIndex, clob);
if (logger.isDebugEnabled()) {
logger.debug(asciiStream != null ?
"Copied ASCII stream into temporary CLOB with length " + contentLength :
"Set CLOB to null");
}
}
示例5: setClobAsCharacterStream
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
@Override
public void setClobAsCharacterStream(
PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength)
throws SQLException {
Clob clob = ps.getConnection().createClob();
try {
FileCopyUtils.copy(characterStream, clob.setCharacterStream(1));
}
catch (IOException ex) {
throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
}
this.temporaryClobs.add(clob);
ps.setClob(paramIndex, clob);
if (logger.isDebugEnabled()) {
logger.debug(characterStream != null ?
"Copied character stream into temporary CLOB with length " + contentLength :
"Set CLOB to null");
}
}
示例6: setClobAsString
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
@Override
public void setClobAsString(PreparedStatement ps, int paramIndex, final String content)
throws SQLException {
if (content != null) {
Clob clob = (Clob) createLob(ps, true, new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getMethod("getCharacterOutputStream", (Class[]) null);
Writer writer = (Writer) methodToInvoke.invoke(lob, (Object[]) null);
FileCopyUtils.copy(content, writer);
}
});
ps.setClob(paramIndex, clob);
if (logger.isDebugEnabled()) {
logger.debug("Set string for Oracle CLOB with length " + clob.length());
}
}
else {
ps.setClob(paramIndex, (Clob) null);
logger.debug("Set Oracle CLOB to null");
}
}
示例7: setClobAsAsciiStream
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
@Override
public void setClobAsAsciiStream(
PreparedStatement ps, int paramIndex, final InputStream asciiStream, int contentLength)
throws SQLException {
if (asciiStream != null) {
Clob clob = (Clob) createLob(ps, true, new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getMethod("getAsciiOutputStream", (Class[]) null);
OutputStream out = (OutputStream) methodToInvoke.invoke(lob, (Object[]) null);
FileCopyUtils.copy(asciiStream, out);
}
});
ps.setClob(paramIndex, clob);
if (logger.isDebugEnabled()) {
logger.debug("Set ASCII stream for Oracle CLOB with length " + clob.length());
}
}
else {
ps.setClob(paramIndex, (Clob) null);
logger.debug("Set Oracle CLOB to null");
}
}
示例8: setClobAsCharacterStream
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
@Override
public void setClobAsCharacterStream(
PreparedStatement ps, int paramIndex, final Reader characterStream, int contentLength)
throws SQLException {
if (characterStream != null) {
Clob clob = (Clob) createLob(ps, true, new LobCallback() {
@Override
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getMethod("getCharacterOutputStream", (Class[]) null);
Writer writer = (Writer) methodToInvoke.invoke(lob, (Object[]) null);
FileCopyUtils.copy(characterStream, writer);
}
});
ps.setClob(paramIndex, clob);
if (logger.isDebugEnabled()) {
logger.debug("Set character stream for Oracle CLOB with length " + clob.length());
}
}
else {
ps.setClob(paramIndex, (Clob) null);
logger.debug("Set Oracle CLOB to null");
}
}
示例9: run
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
@Override
public void run(ApplicationArguments args) throws Exception {
if (ShellUtils.hasHelpOption(args)) {
String usageInstructions;
final Reader reader = new InputStreamReader(getInputStream(HelpAwareShellApplicationRunner.class, "/usage.txt"));
try {
usageInstructions = FileCopyUtils.copyToString(new BufferedReader(reader));
usageInstructions.replaceAll("(\\r|\\n)+", System.getProperty("line.separator"));
}
catch (Exception ex) {
throw new IllegalStateException("Cannot read stream", ex);
}
System.out.println(usageInstructions);
}
}
示例10: 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"));
};
}
示例11: unpackZip
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
private static void unpackZip(ZipFile zipFile, File unpackDir) throws IOException {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File destination = new File(unpackDir.getAbsolutePath() + "/" + entry.getName());
if (entry.isDirectory()) {
destination.mkdirs();
} else {
destination.getParentFile().mkdirs();
FileCopyUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(destination));
}
if (entry.getTime() != -1) {
destination.setLastModified(entry.getTime());
}
}
}
示例12: 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();
}
}
示例13: saveContent
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
public void saveContent(String transferId, String contentFileId, InputStream contentStream)
throws TransferException
{
Lock lock = checkLock(transferId);
try
{
File stagedFile = new File(getStagingFolder(transferId), contentFileId);
if (stagedFile.createNewFile())
{
FileCopyUtils.copy(contentStream, new BufferedOutputStream(new FileOutputStream(stagedFile)));
}
}
catch (Exception ex)
{
throw new TransferException(MSG_ERROR_WHILE_STAGING_CONTENT, new Object[]{transferId, contentFileId}, ex);
}
finally
{
lock.enableLockTimeout();
}
}
示例14: saveContentInUtf8File
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
/**
* Populates a file with the content in the reader, but also converts the encoding to UTF-8.
*/
private void saveContentInUtf8File(ContentReader reader, File file)
{
String encoding = reader.getEncoding();
try
{
Reader in = new InputStreamReader(reader.getContentInputStream(), encoding);
Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), "UTF-8");
FileCopyUtils.copy(in, out); // both streams are closed
}
catch (IOException e)
{
throw new ContentIOException("Failed to copy content to file and convert "+encoding+" to UTF-8: \n" +
" file: " + file,
e);
}
}
示例15: getContent
import org.springframework.util.FileCopyUtils; //導入依賴的package包/類
/**
* Copies the {@link #getContentInputStream() input stream} to the given
* <code>OutputStream</code>
*/
public final void getContent(OutputStream os) throws ContentIOException
{
try
{
InputStream is = getContentInputStream();
FileCopyUtils.copy(is, os); // both streams are closed
// done
}
catch (IOException e)
{
throw new ContentIOException("Failed to copy content to output stream: \n" +
" accessor: " + this,
e);
}
}