View | Details | Raw Unified | Return to bug 137336 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/update/internal/core/JarDeltaInstallHandler.java (-8 / +34 lines)
Lines 18-24 Link Here
18
import java.io.InputStream;
18
import java.io.InputStream;
19
import java.net.URI;
19
import java.net.URI;
20
import java.net.URISyntaxException;
20
import java.net.URISyntaxException;
21
import java.nio.channels.FileChannel;
22
import java.util.Date;
21
import java.util.Date;
23
import java.util.Enumeration;
22
import java.util.Enumeration;
24
import java.util.jar.JarFile;
23
import java.util.jar.JarFile;
Lines 90-104 Link Here
90
			newJarFile.delete();
89
			newJarFile.delete();
91
			
90
			
92
			newJarFile.createNewFile();
91
			newJarFile.createNewFile();
93
			
92
94
			FileChannel in = new FileInputStream(tempFile).getChannel();
93
			copyFile(tempFile, newJarFile);
95
			FileChannel out = new FileOutputStream(newJarFile).getChannel();
96
			in.transferTo( 0, in.size(), out);
97
			
98
			in.close();
99
			out.close();
100
	}
94
	}
101
	
95
	
96
	static boolean useNioCopy = true;
97
	public static void copyFile(File src, File dst) throws IOException {
98
		if (useNioCopy) {
99
			try {
100
				NioHelper.copyFile(src, dst);
101
				return;
102
			} catch (NoSuchMethodError e) {
103
				// fall through
104
			} catch (NoClassDefFoundError e) {
105
				// fall through
106
			}
107
			useNioCopy = false;
108
		}
109
		
110
		FileInputStream in=null;
111
		FileOutputStream out=null;
112
		try {
113
			in = new FileInputStream(src);
114
			out = new FileOutputStream(dst);		
115
			byte[] buffer = new byte[4096];
116
			int len;
117
			while ((len=in.read(buffer)) != -1) {
118
				out.write(buffer, 0, len);
119
			}
120
		} finally {
121
			if (in != null)
122
				in.close();
123
			if (out != null)
124
				out.close();
125
		}
126
	}
127
102
	public static void addToJar(JarOutputStream jos, JarFile jf) throws IOException {
128
	public static void addToJar(JarOutputStream jos, JarFile jf) throws IOException {
103
		Enumeration e = jf.entries();
129
		Enumeration e = jf.entries();
104
		
130
		
(-)src/org/eclipse/update/internal/core/NioHelper.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.update.internal.core;
13
import java.io.File;
14
import java.io.FileInputStream;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
17
import java.nio.channels.FileChannel;
18
19
20
public class NioHelper {
21
	// This method must be in a seperate class file otherwise a NIO class not found error
22
	//  will be thrown loading the calling class.  We put it in it's own class so the
23
	//  caller can catch the error/exception.
24
	static void copyFile(File src, File dst) throws IOException {
25
		FileChannel in = null;
26
		FileChannel out = null; 
27
		
28
		try {
29
			in = new FileInputStream(src).getChannel();
30
			out = new FileOutputStream(dst).getChannel();
31
			in.transferTo( 0, in.size(), out);
32
		} finally {
33
			if (in != null)
34
				in.close();
35
			if (out != null) 
36
				out.close();
37
		}
38
	}
39
40
41
}

Return to bug 137336