Author: aadamchik
Date: Thu Jul 5 20:47:10 2012
New Revision: 1357895
URL: http://svn.apache.org/viewvc?rev=1357895&view=rev
Log:
CAY-1718 Remove everything deprecated in 3.1
in progress
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/UtilTest.java
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java?rev=1357895&r1=1357894&r2=1357895&view=diff
==============================================================================
---
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java
(original)
+++
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/Util.java
Thu Jul 5 20:47:10 2012
@@ -19,20 +19,14 @@
package org.apache.cayenne.util;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
@@ -125,137 +119,6 @@ public class Util {
}
/**
- * Copies file contents from source to destination. Makes up for the lack
of file
- * copying utilities in Java
- *
- * @deprecated since 3.1 this method is not used by Cayenne
- */
- @Deprecated
- public static boolean copy(File source, File destination) {
- BufferedInputStream fin = null;
- BufferedOutputStream fout = null;
- try {
- int bufSize = 8 * 1024;
- fin = new BufferedInputStream(new FileInputStream(source),
bufSize);
- fout = new BufferedOutputStream(new FileOutputStream(destination),
bufSize);
- copyPipe(fin, fout, bufSize);
- }
- catch (IOException ioex) {
- return false;
- }
- catch (SecurityException sx) {
- return false;
- }
- finally {
- if (fin != null) {
- try {
- fin.close();
- }
- catch (IOException cioex) {
- }
- }
- if (fout != null) {
- try {
- fout.close();
- }
- catch (IOException cioex) {
- }
- }
- }
- return true;
- }
-
- /**
- * Save URL contents to a file.
- *
- * @deprecated since 3.1 this method is not used by Cayenne.
- */
- @Deprecated
- public static boolean copy(URL from, File to) {
- BufferedInputStream urlin = null;
- BufferedOutputStream fout = null;
- try {
- int bufSize = 8 * 1024;
- urlin = new BufferedInputStream(
- from.openConnection().getInputStream(),
- bufSize);
- fout = new BufferedOutputStream(new FileOutputStream(to), bufSize);
- copyPipe(urlin, fout, bufSize);
- }
- catch (IOException ioex) {
- return false;
- }
- catch (SecurityException sx) {
- return false;
- }
- finally {
- if (urlin != null) {
- try {
- urlin.close();
- }
- catch (IOException cioex) {
- }
- }
- if (fout != null) {
- try {
- fout.close();
- }
- catch (IOException cioex) {
- }
- }
- }
- return true;
- }
-
- /**
- * Reads data from the input and writes it to the output, until the end of
the input
- * stream.
- *
- * @deprecated since 3.1 this method is unused by Cayenne.
- */
- @Deprecated
- public static void copyPipe(InputStream in, OutputStream out, int
bufSizeHint)
- throws IOException {
- int read = -1;
- byte[] buf = new byte[bufSizeHint];
- while ((read = in.read(buf, 0, bufSizeHint)) >= 0) {
- out.write(buf, 0, read);
- }
- out.flush();
- }
-
- /**
- * Deletes a file or directory, allowing recursive directory deletion.
This is an
- * improved version of File.delete() method.
- *
- * @deprecated since 3.1 this method is unused by Cayenne.
- */
- @Deprecated
- public static boolean delete(String filePath, boolean recursive) {
- File file = new File(filePath);
- if (!file.exists()) {
- return true;
- }
-
- if (!recursive || !file.isDirectory())
- return file.delete();
-
- String[] contents = file.list();
-
- // list can be null if directory doesn't have an 'x' permission bit
set for the
- // user
- if (contents != null) {
- for (String item : contents) {
- if (!delete(filePath + File.separator + item, true)) {
- return false;
- }
- }
- }
-
- return file.delete();
- }
-
- /**
* Replaces all backslashes "\" with forward slashes "/". Convenience
method to
* convert path Strings to URI format.
*/
@@ -467,39 +330,6 @@ public class Util {
}
/**
- * @deprecated since 3.1 in favor of {@link #stripLineBreaks(String,
char)}.
- * @since 1.2
- */
- @Deprecated
- public static String stripLineBreaks(String string, String replaceWith) {
- if (isEmptyString(string)) {
- return string;
- }
-
- int len = string.length();
- StringBuilder buffer = new StringBuilder(len);
- for (int i = 0; i < len; i++) {
- char c = string.charAt(i);
-
- // skip \n, \r, \r\n
- switch (c) {
- case '\n':
- case '\r': // do lookahead
- if (i + 1 < len && string.charAt(i + 1) == '\n') {
- i++;
- }
-
- buffer.append(replaceWith);
- break;
- default:
- buffer.append(c);
- }
- }
-
- return buffer.toString();
- }
-
- /**
* Strips "\n", "\r\n", "\r" from the argument string, replacing them with
a provided
* character.
*
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/UtilTest.java
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/UtilTest.java?rev=1357895&r1=1357894&r2=1357895&view=diff
==============================================================================
---
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/UtilTest.java
(original)
+++
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/UtilTest.java
Thu Jul 5 20:47:10 2012
@@ -21,9 +21,6 @@ package org.apache.cayenne.util;
import java.io.File;
import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.Map;
import junit.framework.TestCase;
@@ -66,8 +63,9 @@ public class UtilTest extends TestCase {
assertEquals(String[].class.getName(), Util
.getJavaClass("java.lang.String[]")
.getName());
- assertEquals(new UtilTest[0].getClass().getName(), Util.getJavaClass(
- getClass().getName() + "[]").getName());
+ assertEquals(
+ new UtilTest[0].getClass().getName(),
+ Util.getJavaClass(getClass().getName() + "[]").getName());
}
public void testToMap() {
@@ -107,13 +105,14 @@ public class UtilTest extends TestCase {
public void testStripLineBreaks() {
// no breaks
- assertEquals("PnMusdkams34 H AnYtk M", Util.stripLineBreaks(
+ assertEquals(
"PnMusdkams34 H AnYtk M",
- 'A'));
+ Util.stripLineBreaks("PnMusdkams34 H AnYtk M", 'A'));
// Windows
- assertEquals("TyusdsdsdQaAbAc", Util
- .stripLineBreaks("TyusdsdsdQa\r\nb\r\nc", 'A'));
+ assertEquals(
+ "TyusdsdsdQaAbAc",
+ Util.stripLineBreaks("TyusdsdsdQa\r\nb\r\nc", 'A'));
// Mac
assertEquals("aBbBc", Util.stripLineBreaks("a\rb\rc", 'B'));
@@ -122,86 +121,6 @@ public class UtilTest extends TestCase {
assertEquals("aCbCc", Util.stripLineBreaks("a\nb\nc", 'C'));
}
- public void testCopyFile() throws java.lang.Exception {
- assertFalse("Temp file "
- + fTmpFileCopy
- + " is on the way, please delete it manually.",
fTmpFileCopy.exists());
- assertTrue(Util.copy(fTmpFileInCurrentDir, fTmpFileCopy));
- assertTrue(fTmpFileCopy.exists());
- assertEquals(fTmpFileCopy.length(), fTmpFileInCurrentDir.length());
- }
-
- public void testCopyFileUrl() throws java.lang.Exception {
- assertFalse("Temp file "
- + fTmpFileCopy
- + " is on the way, please delete it manually.",
fTmpFileCopy.exists());
- assertTrue(Util.copy(fTmpFileInCurrentDir.toURL(), fTmpFileCopy));
- assertTrue(fTmpFileCopy.exists());
- assertEquals(fTmpFileCopy.length(), fTmpFileInCurrentDir.length());
- }
-
- public void testCopyJarUrl() throws Exception {
- URL fileInJar =
getClass().getClassLoader().getResource("testfile1.txt");
- assertNotNull(fileInJar);
-
- // skipping test if file not in jar
- if (!fileInJar.toExternalForm().startsWith("jar:")) {
- return;
- }
-
- assertTrue(Util.copy(fileInJar, fTmpFileCopy));
- assertTrue(fTmpFileCopy.exists());
-
- // check file size in a jar
- InputStream in = null;
- try {
- in = fileInJar.openConnection().getInputStream();
- int len = 0;
- while (in.read() >= 0) {
- len++;
- }
- assertEquals(len, fTmpFileCopy.length());
- }
- catch (IOException ioex) {
- fail();
- }
- finally {
- if (in != null)
- in.close();
- }
-
- }
-
- public void testDeleteFile() throws Exception {
- // delete file
- assertFalse("Temp file "
- + fTmpFileCopy
- + " is on the way, please delete it manually.",
fTmpFileCopy.exists());
- Util.copy(fTmpFileInCurrentDir, fTmpFileCopy);
- assertTrue(Util.delete(fTmpFileCopy.getPath(), false));
-
- // delete empty dir with no recursion
- String tmpDirName = "tmpdir_" + System.currentTimeMillis();
- File tmpDir = new File(tmpDirName);
- assertTrue(tmpDir.mkdir());
- assertTrue(Util.delete(tmpDirName, false));
- assertFalse(tmpDir.exists());
-
- // delete dir with files with recurions
- assertTrue(tmpDir.mkdir());
- assertTrue(new File(tmpDir, "aaa").createNewFile());
- assertTrue(Util.delete(tmpDirName, true));
- assertFalse(tmpDir.exists());
-
- // fail delete dir with files with no recurions
- assertTrue(tmpDir.mkdir());
- assertTrue(new File(tmpDir, "aaa").createNewFile());
- assertFalse(Util.delete(tmpDirName, false));
- assertTrue(tmpDir.exists());
- assertTrue(Util.delete(tmpDirName, true));
- assertFalse(tmpDir.exists());
- }
-
public void testCloneViaSerialization() throws Exception {
// need a special subclass of Object to make "clone" method public
MockSerializable o1 = new MockSerializable();