svn commit: r789570 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util: Ascii.java Base64.java
Author: mturk Date: Tue Jun 30 06:14:13 2009 New Revision: 789570 URL: http://svn.apache.org/viewvc?rev=789570view=rev Log: Use byte and char arrays instead casting Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Base64.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java?rev=789570r1=789569r2=789570view=diff == --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Ascii.java Tue Jun 30 06:14:13 2009 @@ -23,6 +23,7 @@ * Character Classification routines. * * @author Mladen Turk + * @since Runtime 1.0 */ public final class Ascii { Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Base64.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Base64.java?rev=789570r1=789569r2=789570view=diff == --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Base64.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Base64.java Tue Jun 30 06:14:13 2009 @@ -19,7 +19,14 @@ import java.io.UnsupportedEncodingException; /** - * Base64 encoding enumeration + * Provides Base64 encoding and decoding as defined by {...@code RFC 2045}. + * p + * This class implements section cite6.8. Base64 Content-Transfer-Encoding/cite + * from RFC 2045 citeMultipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies/cite + * by Freed and Borenstein. + * /p + * + * @see a href=http://www.ietf.org/rfc/rfc2045.txt;RFC 2045/a * * @author Mladen Turk * @@ -33,12 +40,29 @@ } /** - * Wrap encoded lines after {...@code COLS} character {...@code (default 72)}. + * Wrap encoded lines after {...@value} character. + * p + * The {...@value} character limit does not count the trailing {...@code CRLF}, + * but counts all other characters, including any equal signs. + * /p + * + * @see a href=http://www.ietf.org/rfc/rfc2045.txt;RFC 2045 section 6.8/a */ -public static final intCOLS= 72; +public static final intCOLS= 76; +private static final String CHARSET = ISO-8859-1; private static final char padding = '='; +private static final char CR = '\r'; private static final char LF = '\n'; -private static final char[] basis64 = { +private static final byte[] base64b = { +'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', +'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', +'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', +'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', +'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', +'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', +'8', '9', '+', '/' +}; +private static final char[] base64c = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', @@ -50,9 +74,9 @@ // ASCII table private static final byte[] pr2six = { -65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 63, 65, 65, 65, 65, 65, +65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 64, 65, 65, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, -65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 62, 65, 65, 65, 64, +65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 62, 65, 65, 65, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 65, 65, 65, 65, 65, 65, 65, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 65, 65, 65, 65, 65, @@ -85,11 +109,13 @@ { int dstlen; +if (len 1) +len = src.length - srcPos; dstlen = (((len + 2) / 3) * 4); if (wrap == -1) wrap = COLS; if (wrap 0) -dstlen += (dstlen / wrap); +dstlen += ((dstlen / wrap) * 2); return dstlen; } @@ -106,6 +132,8 @@ int[] inp = new int[3]; int[] out = new int[4]; +if (len 1) +len = src.length - srcPos; if (wrap == -1) wrap = COLS; while (len = 3) { @@ -121,13 +149,15 @@ if (dp + 4 dl) throw new IndexOutOfBoundsException(Destination is too small); -dst[dp++] =
svn commit: r789573 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/StringUtils.java test/org/apache/commons/lang/StringUtilsTest.java
Author: bayard Date: Tue Jun 30 06:24:20 2009 New Revision: 789573 URL: http://svn.apache.org/viewvc?rev=789573view=rev Log: Applying Vincent Ricard's patch in LANG-471 (reported by Ivica Mikic) adding isAllUpperCase and isAllLowerCase to StringUtils Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=789573r1=789572r2=789573view=diff == --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Tue Jun 30 06:24:20 2009 @@ -4916,6 +4916,66 @@ return true; } +/** + * pChecks if the String contains only lowercase characters./p + * + * pcodenull/code will return codefalse/code. + * An empty String () will return codefalse/code./p + * + * pre + * StringUtils.isAllLowerCase(null) = false + * StringUtils.isAllLowerCase() = false + * StringUtils.isAllLowerCase( ) = false + * StringUtils.isAllLowerCase(abc) = true + * StringUtils.isAllLowerCase(abC) = false + * /pre + * + * @param str the String to check, may be null + * @return codetrue/code if only contains lowercase characters, and is non-null + */ +public static boolean isAllLowerCase(String str) { +if (str == null || isEmpty(str)) { +return false; +} +int sz = str.length(); +for (int i = 0; i sz; i++) { +if (Character.isLowerCase(str.charAt(i)) == false) { +return false; +} +} +return true; +} + +/** + * pChecks if the String contains only uppercase characters./p + * + * pcodenull/code will return codefalse/code. + * An empty String () will return codefalse/code./p + * + * pre + * StringUtils.isAllUpperCase(null) = false + * StringUtils.isAllUpperCase() = false + * StringUtils.isAllUpperCase( ) = false + * StringUtils.isAllUpperCase(ABC) = true + * StringUtils.isAllUpperCase(aBC) = false + * /pre + * + * @param str the String to check, may be null + * @return codetrue/code if only contains uppercase characters, and is non-null + */ +public static boolean isAllUpperCase(String str) { +if (str == null || isEmpty(str)) { +return false; +} +int sz = str.length(); +for (int i = 0; i sz; i++) { +if (Character.isUpperCase(str.charAt(i)) == false) { +return false; +} +} +return true; +} + // Defaults //--- /** Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java?rev=789573r1=789572r2=789573view=diff == --- commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java (original) +++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java Tue Jun 30 06:24:20 2009 @@ -1541,7 +1541,29 @@ assertEquals(, StringUtils.EMPTY); assertEquals(0, StringUtils.EMPTY.length()); } - + +/** + * Test for {...@link StringUtils#isAllLowerCase(String)}. + */ +public void testIsAllLowerCase() { +assertFalse(StringUtils.isAllLowerCase(null)); +assertFalse(StringUtils.isAllLowerCase(StringUtils.EMPTY)); +assertTrue(StringUtils.isAllLowerCase(abc)); +assertFalse(StringUtils.isAllLowerCase(abc )); +assertFalse(StringUtils.isAllLowerCase(abC)); +} + +/** + * Test for {...@link StringUtils#isAllUpperCase(String)}. + */ +public void testIsAllUpperCase() { +assertFalse(StringUtils.isAllUpperCase(null)); +assertFalse(StringUtils.isAllUpperCase(StringUtils.EMPTY)); +assertTrue(StringUtils.isAllUpperCase(ABC)); +assertFalse(StringUtils.isAllUpperCase(ABC )); +assertFalse(StringUtils.isAllUpperCase(aBC)); +} + public void testRemoveStart() { // StringUtils.removeStart(, *)= assertNull(StringUtils.removeStart(null, null));
svn commit: r789575 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
Author: bayard Date: Tue Jun 30 06:34:01 2009 New Revision: 789575 URL: http://svn.apache.org/viewvc?rev=789575view=rev Log: Moving a few of the StringUtils methods over to accepting CharSequence instead of String as part of LANG-510 Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=789575r1=789574r2=789575view=diff == --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Tue Jun 30 06:34:01 2009 @@ -188,7 +188,7 @@ * @param str the String to check, may be null * @return codetrue/code if the String is empty or null */ -public static boolean isEmpty(String str) { +public static boolean isEmpty(CharSequence str) { return str == null || str.length() == 0; } @@ -206,7 +206,7 @@ * @param str the String to check, may be null * @return codetrue/code if the String is not empty and not null */ -public static boolean isNotEmpty(String str) { +public static boolean isNotEmpty(CharSequence str) { return !StringUtils.isEmpty(str); } @@ -225,7 +225,7 @@ * @return codetrue/code if the String is null, empty or whitespace * @since 2.0 */ -public static boolean isBlank(String str) { +public static boolean isBlank(CharSequence str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; @@ -254,7 +254,7 @@ * not empty and not null and not whitespace * @since 2.0 */ -public static boolean isNotBlank(String str) { +public static boolean isNotBlank(CharSequence str) { return !StringUtils.isBlank(str); }
svn commit: r789584 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate: EntityArrays.java EscapeUtils.java UnescapeUtils.java
Author: bayard Date: Tue Jun 30 06:47:18 2009 New Revision: 789584 URL: http://svn.apache.org/viewvc?rev=789584view=rev Log: Making the EntityArrays class public by cloning the arrays when they are accessed. API might need a sanity check as this is the old Entities stuff. Also changing the arrays to be private and the rest of the code to use the cloning methods. This does add performance overhead, but I think it'll be negligible and better to practice safe coding. Part of LANG-505 Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java?rev=789584r1=789583r2=789584view=diff == --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java Tue Jun 30 06:47:18 2009 @@ -17,15 +17,16 @@ package org.apache.commons.lang.text.translate; /** - * Package private class holding varius entity data for HTML and XML. + * Class holding various entity data for HTML and XML - generally for use with + * the LookupTranslator. * All arrays are of length [*][2]. * * @since 3.0 */ -// TODO: These need to be public - make methods to return them for security purposes? -class EntityArrays { +public class EntityArrays { -static final String[][] ISO8859_1_ESCAPE = { +public static String[][] ISO8859_1_ESCAPE() { return ISO8859_1_ESCAPE.clone(); } +private static final String[][] ISO8859_1_ESCAPE = { {\u00A0, nbsp;}, // non-breaking space {\u00A1, iexcl;}, // inverted exclamation mark {\u00A2, cent;}, // cent sign @@ -124,10 +125,12 @@ {\u00FF, yuml;}, // ΓΏ - lowercase y, umlaut }; -static final String[][] ISO8859_1_UNESCAPE = invert(ISO8859_1_ESCAPE); +public static String[][] ISO8859_1_UNESCAPE() { return ISO8859_1_UNESCAPE.clone(); } +private static final String[][] ISO8859_1_UNESCAPE = invert(ISO8859_1_ESCAPE); // http://www.w3.org/TR/REC-html40/sgml/entities.html -static final String[][] HTML40_EXTENDED_ESCAPE = { +public static String[][] HTML40_EXTENDED_ESCAPE() { return HTML40_EXTENDED_ESCAPE.clone(); } +private static final String[][] HTML40_EXTENDED_ESCAPE = { // !-- Latin Extended-B -- {\u0192, fnof;}, // latin small f with hook = function= florin, U+0192 ISOtech -- // !-- Greek -- @@ -324,29 +327,34 @@ {\u20AC, euro;}, // -- euro sign, U+20AC NEW -- }; -static final String[][] HTML40_EXTENDED_UNESCAPE = invert(HTML40_EXTENDED_ESCAPE); +public static String[][] HTML40_EXTENDED_UNESCAPE() { return HTML40_EXTENDED_UNESCAPE.clone(); } +private static final String[][] HTML40_EXTENDED_UNESCAPE = invert(HTML40_EXTENDED_ESCAPE); -static final String[][] BASIC_ESCAPE = { +public static String[][] BASIC_ESCAPE() { return BASIC_ESCAPE.clone(); } +private static final String[][] BASIC_ESCAPE = { {\, quot;}, // - double-quote {, amp;}, // - ampersand {, lt;},// - less-than {, gt;},// - greater-than }; -static final String[][] BASIC_UNESCAPE = invert(BASIC_ESCAPE); +public static String[][] BASIC_UNESCAPE() { return BASIC_UNESCAPE.clone(); } +private static final String[][] BASIC_UNESCAPE = invert(BASIC_ESCAPE); -static final String[][] APOS_ESCAPE = { +public static String[][] APOS_ESCAPE() { return APOS_ESCAPE.clone(); } +private static final String[][] APOS_ESCAPE = { {', apos;}, // XML apostrophe }; -static final String[][] APOS_UNESCAPE = invert(APOS_ESCAPE); +public static String[][] APOS_UNESCAPE() { return APOS_UNESCAPE.clone(); } +private static final String[][] APOS_UNESCAPE = invert(APOS_ESCAPE); /** * Used to invert an escape array into an unescape array * @param array String[][] to be inverted * @return String[][] inverted array */ -static String[][] invert(String[][] array) { +public static String[][] invert(String[][] array) { String[][] newarray = new String[array.length][2]; for(int i = 0; iarray.length; i++) { newarray[i][0] = array[i][1]; Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java URL:
svn commit: r789588 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/io/File.java main/native/include/acr_error.h main/native/os/unix/file.c main/native/test/testcase.c te
Author: mturk Date: Tue Jun 30 06:58:12 2009 New Revision: 789588 URL: http://svn.apache.org/viewvc?rev=789588view=rev Log: Make sure we throw exception after string cleanup Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c commons/sandbox/runtime/trunk/src/main/native/test/testcase.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=789588r1=789587r2=789588view=diff == --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Tue Jun 30 06:58:12 2009 @@ -39,6 +39,8 @@ throws IOException, SecurityException; private static native int fprot0(String pathname) throws IOException, SecurityException; +private static native long inode0(String pathname) +throws IOException, SecurityException; private static native boolean fprot1(String pathname, int prot) throws IOException, SecurityException; private static native boolean fprot2(String pathname, @@ -447,9 +449,19 @@ return new File(getTargetPath()); } +/** + * Return this abstract {...@code File} system id. + * + * @return Existing {...@code File} system id. + * @throws IOException if this {...@code File} is not symbolic or hard link + * or an I/O error occured. + * @throws SecurityException if search permission is denied for a + * component of this abstract {...@code File} pathname prefix. + */ public long fileId() +throws IOException, SecurityException { -return 0L; +return inode0(getPath()); } } Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=789588r1=789587r2=789588view=diff == --- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Tue Jun 30 06:58:12 2009 @@ -123,9 +123,8 @@ #endif #else -static int _seh_error = 0; #define ACR_TRY -#define ACR_CATCH() if (_seh_error) +#define ACR_CATCH() if (0) #endif /* HAVE_MEMPROTECT */ Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=789588r1=789587r2=789588view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Tue Jun 30 06:58:12 2009 @@ -123,29 +123,61 @@ return type; } +ACR_IO_EXPORT_DECLARE(jlong, File, inode0)(ACR_JNISTDARGS, jstring pathname) +{ +jlong rv = 0; +int ex = EINVAL; + +UNREFERENCED_O; +WITH_CSTR(pathname) { +struct_stat info; + +if ((ex = stat(J2S(pathname), info)) == 0) { +rv = (jlong)info.st_ino; +} +else +ex = ACR_GET_OS_ERROR(); +} END_WITH_CSTR(pathname); + +if (ex) { +if (ACR_STATUS_IS_EACCES(ex)) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0); +} +else if (!ACR_STATUS_IS_EEXIST(ex)) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex); +} +} +return rv; +} + ACR_IO_EXPORT_DECLARE(jboolean, File, mkslink0)(ACR_JNISTDARGS, jstring target, jstring lnkname) { jboolean rc = JNI_FALSE; +int ex = EINVAL; UNREFERENCED_O; WITH_CSTR(target) { WITH_CSTR(lnkname) { if (symlink(J2S(target), J2S(lnkname))) { -int err = ACR_GET_OS_ERROR(); -if (ACR_STATUS_IS_EACCES(err)) { -ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0); -} -else if (!ACR_STATUS_IS_EEXIST(err)) { -ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, err); -} +ex = ACR_GET_OS_ERROR(); } -else +else { +ex = 0; rc = JNI_TRUE; +} }
svn commit: r789589 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate: EscapeUtils.java UnescapeUtils.java
Author: bayard Date: Tue Jun 30 07:04:06 2009 New Revision: 789589 URL: http://svn.apache.org/viewvc?rev=789589view=rev Log: Splitting out the \b \n \t \f \r Java ctrl chars as their own translator to help with the request in LANG-498 Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java?rev=789589r1=789588r2=789589view=diff == --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java Tue Jun 30 07:04:06 2009 @@ -29,12 +29,7 @@ */ public class EscapeUtils { -public static final CharSequenceTranslator ESCAPE_JAVA = - new LookupTranslator( -new String[][] { - {\, \\\}, - {\\, }, - }).with( +public static final CharSequenceTranslator ESCAPE_JAVA_CTRL_CHARS = new LookupTranslator( new String[][] { {\b, \\b}, @@ -42,9 +37,18 @@ {\t, \\t}, {\f, \\f}, {\r, \\r} +}); + +public static final CharSequenceTranslator ESCAPE_JAVA = + new LookupTranslator( +new String[][] { + {\, \\\}, + {\\, }, }).with( - UnicodeEscaper.outsideOf(32, 0x7f) -)); +ESCAPE_JAVA_CTRL_CHARS + ).with( +UnicodeEscaper.outsideOf(32, 0x7f) +); public static final String escapeJava(String input) { return ESCAPE_JAVA.translate(input); @@ -59,14 +63,7 @@ {\\, }, {/, \\/} }), -new LookupTranslator( - new String[][] { -{\b, \\b}, -{\n, \\n}, -{\t, \\t}, -{\f, \\f}, -{\r, \\r} - }), +ESCAPE_JAVA_CTRL_CHARS, UnicodeEscaper.outsideOf(32, 0x7f) ); Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java?rev=789589r1=789588r2=789589view=diff == --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java Tue Jun 30 07:04:06 2009 @@ -29,20 +29,26 @@ */ public class UnescapeUtils { +public static final CharSequenceTranslator UNESCAPE_JAVA_CTRL_CHARS = +new LookupTranslator( + new String[][] { +{\\b, \b}, +{\\n, \n}, +{\\t, \t}, +{\\f, \f}, +{\\r, \r} + }); + // throw illegal character: \92 as an Exception if a \ on the end of the Java (as per the compiler)? public static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator( new UnicodeUnescaper(), +UNESCAPE_JAVA_CTRL_CHARS, new LookupTranslator( new String[][] { {, \\}, {\\\, \}, {\\', '}, -{\\r, \r}, -{\\f, \f}, -{\\t, \t}, -{\\n, \n}, -{\\b, \b}, {\\, } }) );
svn commit: r789597 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
Author: bodewig Date: Tue Jun 30 07:25:44 2009 New Revision: 789597 URL: http://svn.apache.org/viewvc?rev=789597view=rev Log: clear block after write to avoid garbage in the final block if it isn't full. COMPRESS-81. Merge from Ant. Modified: commons/proper/compress/trunk/src/changes/changes.xml commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java (contents, props changed) Modified: commons/proper/compress/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=789597r1=789596r2=789597view=diff == --- commons/proper/compress/trunk/src/changes/changes.xml (original) +++ commons/proper/compress/trunk/src/changes/changes.xml Tue Jun 30 07:25:44 2009 @@ -20,11 +20,15 @@ document properties titlecommons-compress/title -authorStefan Bodewig/author /properties body -release version=1.0 date=as in SVN description=First Public Release - action dev=all type=add +release version=1.1 date=as in SVN description=Release 1.1 + action issue=COMPRESS-81 type=fix date=2009-06-30 +TarOutputStream can leave garbage at the end of the archive + /action +/release +release version=1.0 date=2009-05-21 description=First Public Release + action dev=all type=add date=2009-05-21 Initial release /action action dev=sgoeschl type=fix Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java?rev=789597r1=789596r2=789597view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java Tue Jun 30 07:25:44 2009 @@ -373,6 +373,7 @@ currRecIdx = 0; currBlkIdx++; +Arrays.fill(blockBuffer, (byte) 0); } /** Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java -- --- svn:mergeinfo (added) +++ svn:mergeinfo Tue Jun 30 07:25:44 2009 @@ -0,0 +1 @@ +/ant/core/trunk/src/main/org/apache/tools/tar/TarBuffer.java:741089,789556
svn commit: r789600 - /commons/proper/compress/trunk/src/site/xdoc/index.xml
Author: bodewig Date: Tue Jun 30 07:48:31 2009 New Revision: 789600 URL: http://svn.apache.org/viewvc?rev=789600view=rev Log: there is a release Modified: commons/proper/compress/trunk/src/site/xdoc/index.xml Modified: commons/proper/compress/trunk/src/site/xdoc/index.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/site/xdoc/index.xml?rev=789600r1=789599r2=789600view=diff == --- commons/proper/compress/trunk/src/site/xdoc/index.xml (original) +++ commons/proper/compress/trunk/src/site/xdoc/index.xml Tue Jun 30 07:48:31 2009 @@ -89,7 +89,8 @@ /section section name=Releases p -None. +The latest version v1.0, is JDK 1.4 compatible - +a href=http://commons.apache.org/compress/download_compress.cgi;Download now!/a /p /section /body
svn commit: r789606 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 08:17:22 2009 New Revision: 789606 URL: http://svn.apache.org/viewvc?rev=789606view=rev Log: Always change forward to backward slashes Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789606r1=789605r2=789606view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 08:17:22 2009 @@ -30,6 +30,36 @@ * */ +/* + * 1. Remove \\?\ prefix + * 2. Replace UNC\ with \\ + */ +static __inline wchar_t *NO2UNC(wchar_t *fname) +{ +if (wcsncmp(fname, L?\\, 4) == 0) { +fname += 4; +if (wcsncmp(fname, LUNC\\, 4) == 0) { +fname += 2; +*fname = L'\\'; +} +else if (wcsncmp(fname, LUN, 4) == 0) { +/* Already modified in-place. + */ +fname += 2; +} +} +return fname; +} + +static __inline void FS2BS(wchar_t *path) +{ +size_t i; +for (i = 0; i wcslen(path); i++) { +if (path[i] == L'/') +path[i] = L'\\'; +} +} + ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const wchar_t *fname) { WIN32_FILE_ATTRIBUTE_DATA info; @@ -97,6 +127,7 @@ UNREFERENCED_O; WITH_WSTR(pathname) { +FS2BS(J2W(pathname)); type = ACR_FileTypeGet(_E, J2W(pathname)); } END_WITH_WSTR(pathname); @@ -117,6 +148,7 @@ DWORD dwFlags = 0; size_t tlen = wcslen(J2W(target)); +FS2BS(J2W(target)); if (ACR_FileTypeGet(NULL, J2W(target)) == ACR_FT_DIR) { dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY; } @@ -231,6 +263,8 @@ UNREFERENCED_O; WITH_WSTR(target) { WITH_WSTR(lnkname) { +FS2BS(J2W(target)); +FS2BS(J2W(lnkname)); if (!CreateHardLinkW(J2W(lnkname), J2W(target), NULL)) { int err = ACR_GET_OS_ERROR(); if (ACR_STATUS_IS_EACCES(err)) { @@ -252,10 +286,12 @@ jstring lnkname) { jstring rv = NULL; +int ex = 0; UNREFERENCED_O; WITH_WSTR(lnkname) { void *buf = ACR_Calloc(_E, THROW_FMARK, MAXIMUM_REPARSE_DATA_BUFFER_SIZE); +FS2BS(J2W(lnkname)); if (buf) { HANDLE sh = CreateFileW(J2W(lnkname), GENERIC_READ, @@ -318,19 +354,21 @@ } break; default: -ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ACR_EBADF); +ex = ACR_EBADF; break; } CloseHandle(sh); } else { -ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, -ACR_GET_OS_ERROR()); +ex = ACR_GET_OS_ERROR(); } free(buf); } } END_WITH_WSTR(lnkname); +if (ex) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex); +} return rv; } @@ -427,20 +465,6 @@ int fix = 0; int rc; -if (wcsncmp(fname, L?\\, 4) == 0) { -fname += 4; -if (wcsncmp(fname, LUNC\\, 4) == 0) { -/* TODO: Do not modify in fname in-place. - */ -fname += 2; -*fname = L'\\'; -} -else if (wcsncmp(fname, LUN, 4) == 0) { -/* Already modified in-place. - */ -fname += 2; -} -} rc = GetNamedSecurityInfoW(fname, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, @@ -556,18 +580,6 @@ int fix = 0; int rc; -if (wcsncmp(fname, L?\\, 4) == 0) { -fname += 4; -if (wcsncmp(fname, LUNC\\, 4) == 0) { -fname += 2; -*fname = L'\\'; -} -else if (wcsncmp(fname, LUN, 4) == 0) { -/* Already modified in-place. - */ -fname += 2; -} -} rc = GetNamedSecurityInfoW(fname, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, @@ -621,6 +633,7 @@ UNREFERENCED_O; WITH_WSTR(pathname) { +FS2BS(J2W(pathname)); prot = ACR_FileProtectionGet(_E, J2W(pathname)); } END_WITH_WSTR(pathname); @@ -635,6 +648,7 @@ UNREFERENCED_O; WITH_WSTR(pathname) { +FS2BS(J2W(pathname)); rc = ACR_FileProtectionSet(_E, J2W(pathname), prot); } END_WITH_WSTR(pathname);
svn commit: r789607 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java test/java/org/apache/commons/compress/compresso
Author: bodewig Date: Tue Jun 30 08:23:08 2009 New Revision: 789607 URL: http://svn.apache.org/viewvc?rev=789607view=rev Log: Add a BZip2Utils class matching GZipUtils. Submitted by Jukka Zitting. COMPRESS-78 Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java (with props) commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/BZip2UtilsTestCase.java (with props) Modified: commons/proper/compress/trunk/src/changes/changes.xml Modified: commons/proper/compress/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=789607r1=789606r2=789607view=diff == --- commons/proper/compress/trunk/src/changes/changes.xml (original) +++ commons/proper/compress/trunk/src/changes/changes.xml Tue Jun 30 08:23:08 2009 @@ -26,6 +26,10 @@ action issue=COMPRESS-81 type=fix date=2009-06-30 TarOutputStream can leave garbage at the end of the archive /action + action issue=COMPRESS-78 type=add date=2009-06-30 + due-to=Jukka Zitting +Add a BZip2Utils class modelled after GZipUtils + /action /release release version=1.0 date=2009-05-21 description=First Public Release action dev=all type=add date=2009-05-21 Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java?rev=789607view=auto == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java (added) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java Tue Jun 30 08:23:08 2009 @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.compressors.bzip2; + +import java.util.HashMap; +import java.util.Map; + +/** + * Utility code for the BZip2 compression format. + * @ThreadSafe + * @since Commons Compress 1.1 + */ +public abstract class BZip2Utils { + +/** + * Map from common filename suffixes of bzip2ed files to the corresponding + * suffixes of uncompressed files. For example: from .tbz2 to .tar. + * p + * This map also contains bzip2-specific suffixes like .bz2. These + * suffixes are mapped to the empty string, as they should simply be + * removed from the filename when the file is uncompressed. + */ +private static final Map uncompressSuffix = new HashMap(); + +static { +uncompressSuffix.put(.tbz2, .tar); +uncompressSuffix.put(.tbz, .tar); +uncompressSuffix.put(.bz2, ); +uncompressSuffix.put(.bz, ); +} +// N.B. if any shorter or longer keys are added, ensure the for loop limits are changed + +/** Private constructor to prevent instantiation of this utility class. */ +private BZip2Utils() { +} + +/** + * Detects common bzip2 suffixes in the given filename. + * + * @param filename name of a file + * @return codetrue/code if the filename has a common bzip2 suffix, + * codefalse/code otherwise + */ +public static boolean isCompressedFilename(String filename) { +String lower = filename.toLowerCase(); +int n = lower.length(); +// Shortest suffix is three letters (.bz), longest is five (.tbz2) +for (int i = 3; i = 5 i n; i++) { +if (uncompressSuffix.containsKey(lower.substring(n - i))) { +return true; +} +} +return false; +} + +/** + * Maps the given name of a bzip2-compressed file to the name that the + * file should have after uncompression. Commonly used file type specific + * suffixes like .tbz or .tbz2 are automatically detected and + * correctly mapped. For example the name package.tbz2 is mapped to + * package.tar. And any
svn commit: r789608 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 08:23:33 2009 New Revision: 789608 URL: http://svn.apache.org/viewvc?rev=789608view=rev Log: No need to ckeck for foward slashes. They are already replaced by backward Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789608r1=789607r2=789608view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 08:23:33 2009 @@ -152,8 +152,7 @@ if (ACR_FileTypeGet(NULL, J2W(target)) == ACR_FT_DIR) { dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY; } -else if (tlen 0 (J2W(target)[tlen - 1 ] == L'\\' || - J2W(target)[tlen - 1 ] == L'/')) { +else if (tlen 0 J2W(target)[tlen - 1 ] == L'\\') { dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY; } if (ACR_HAVE_LATE_DLL_FUNC(CreateSymbolicLinkW)) {
svn commit: r789609 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 08:25:50 2009 New Revision: 789609 URL: http://svn.apache.org/viewvc?rev=789609view=rev Log: Directoy name needs at least one char beside backslash Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789609r1=789608r2=789609view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 08:25:50 2009 @@ -152,7 +152,7 @@ if (ACR_FileTypeGet(NULL, J2W(target)) == ACR_FT_DIR) { dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY; } -else if (tlen 0 J2W(target)[tlen - 1 ] == L'\\') { +else if (tlen 1 J2W(target)[tlen - 1 ] == L'\\') { dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORORY; } if (ACR_HAVE_LATE_DLL_FUNC(CreateSymbolicLinkW)) { @@ -186,7 +186,7 @@ goto bailout; } tlen = wcslen(fpath); -if (tlen 0 fpath[tlen - 1] == L'\\') { +if (tlen 1 fpath[tlen - 1] == L'\\') { fpath[--tlen] = L'\0'; } /* Remove the link directory if already exists */
svn commit: r789623 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
Author: mturk Date: Tue Jun 30 08:53:49 2009 New Revision: 789623 URL: http://svn.apache.org/viewvc?rev=789623view=rev Log: Use device number in fileId Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=789623r1=789622r2=789623view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Tue Jun 30 08:53:49 2009 @@ -133,7 +133,7 @@ struct_stat info; if ((ex = stat(J2S(pathname), info)) == 0) { -rv = (jlong)info.st_ino; +rv = ((jlong)info.st_dev 32) + (jlong)info.st_ino; } else ex = ACR_GET_OS_ERROR();
svn commit: r789628 - /commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
Author: mturk Date: Tue Jun 30 09:06:36 2009 New Revision: 789628 URL: http://svn.apache.org/viewvc?rev=789628view=rev Log: Print id (temporary solution) Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=789628r1=789627r2=789628view=diff == --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Tue Jun 30 09:06:36 2009 @@ -283,6 +283,9 @@ long i2 = f2.fileId(); assertTrue(Zero, i1 != 0L); assertTrue(Eqaul, i1 != i2); +System.out.println(); +System.out.println(File 1 id + i1); +System.out.println(File 2 id + i2); f1.delete(); f2.delete();
svn commit: r789634 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 09:23:14 2009 New Revision: 789634 URL: http://svn.apache.org/viewvc?rev=789634view=rev Log: Implement fileId for Windows Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789634r1=789633r2=789634view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 09:23:14 2009 @@ -781,3 +781,44 @@ } } +ACR_IO_EXPORT_DECLARE(jlong, File, inode0)(ACR_JNISTDARGS, jstring pathname) +{ +jlong rv = 0; +int ex = EINVAL; + +UNREFERENCED_O; +WITH_WSTR(pathname) { +HANDLE fh; +FS2BS(J2W(pathname)); + +fh = CreateFileW(J2W(pathname), +GENERIC_READ, +FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, +NULL, +OPEN_EXISTING, +0, +NULL); +if (fh != INVALID_HANDLE_VALUE) { +BY_HANDLE_FILE_INFORMATION fi; +if (GetFileInformationByHandle(fh, fi)) { +rv = (((jlong)fi.nFileIndexHigh + (jlong)fi.dwVolumeSerialNumber) 31) + fi.nFileIndexLow; +ex = 0; +} +else +ex = ACR_GET_OS_ERROR(); +CloseHandle(fh); +} +else +ex = ACR_GET_OS_ERROR(); +} END_WITH_WSTR(pathname); + +if (ex) { +if (ACR_STATUS_IS_EACCES(ex)) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0); +} +else if (!ACR_STATUS_IS_EEXIST(ex)) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex); +} +} +return rv; +}
svn commit: r789656 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 10:32:12 2009 New Revision: 789656 URL: http://svn.apache.org/viewvc?rev=789656view=rev Log: Use zero for access flags according to the MSDN Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789656r1=789655r2=789656view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 10:32:12 2009 @@ -792,12 +792,12 @@ FS2BS(J2W(pathname)); fh = CreateFileW(J2W(pathname), -GENERIC_READ, -FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, -NULL, -OPEN_EXISTING, -0, -NULL); + 0, /* Query attributes without accessing the file */ + 0, + NULL, + OPEN_EXISTING, + 0, + NULL); if (fh != INVALID_HANDLE_VALUE) { BY_HANDLE_FILE_INFORMATION fi; if (GetFileInformationByHandle(fh, fi)) {
svn commit: r789664 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 10:39:03 2009 New Revision: 789664 URL: http://svn.apache.org/viewvc?rev=789664view=rev Log: Guard against already opened files with own sharing flags. Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789664r1=789663r2=789664view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 10:39:03 2009 @@ -793,7 +793,7 @@ fh = CreateFileW(J2W(pathname), 0, /* Query attributes without accessing the file */ - 0, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
svn commit: r789666 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Author: mturk Date: Tue Jun 30 10:41:04 2009 New Revision: 789666 URL: http://svn.apache.org/viewvc?rev=789666view=rev Log: Shift by 30 bits. We can have overflow from both volume and indexLow Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789666r1=789665r2=789666view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 10:41:04 2009 @@ -801,7 +801,7 @@ if (fh != INVALID_HANDLE_VALUE) { BY_HANDLE_FILE_INFORMATION fi; if (GetFileInformationByHandle(fh, fi)) { -rv = (((jlong)fi.nFileIndexHigh + (jlong)fi.dwVolumeSerialNumber) 31) + fi.nFileIndexLow; +rv = (((jlong)fi.nFileIndexHigh + (jlong)fi.dwVolumeSerialNumber) 30) + fi.nFileIndexLow; ex = 0; } else
svn commit: r789743 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/io/File.java main/native/os/unix/file.c test/org/apache/commons/runtime/TestFile.java
Author: mturk Date: Tue Jun 30 14:08:24 2009 New Revision: 789743 URL: http://svn.apache.org/viewvc?rev=789743view=rev Log: Add getFileAttributes method Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=789743r1=789742r2=789743view=diff == --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Tue Jun 30 14:08:24 2009 @@ -55,6 +55,8 @@ throws IOException, SecurityException; private static native boolean attrs0(String pathname, int attr, int mask) throws IOException, SecurityException; +private static native int attrg0(String pathname) +throws IOException, SecurityException; // Cached FileType Enum integer value. private int fileType = -1; @@ -252,6 +254,28 @@ } /** + * Get attributes of the file denoted by this abstract pathname. + * p + * For getting the set of complete file attributes use the + * {...@code getFileProtection } method. + * /p + * pre + * READONLY - file is readonly + * EXECUTABLE - file is executable + * HIDDEN - file is hidden + * /pre + * @return Set of {...@code FileAttributes}. + * @throws IOException If an I/O error occured. + * @throws SecurityException If Search permission is denied for one of + * the directories in the path prefix this {...@code File} path. + */ +public EnumSetFileAttributes getFileAttributes() +throws IOException, SecurityException +{ +return FileAttributes.valueOf(attrg0(getPath())); +} + +/** * Returns {...@code true} if the file denoted by this abstract * pathname is symbolic link. * Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=789743r1=789742r2=789743view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Tue Jun 30 14:08:24 2009 @@ -461,3 +461,31 @@ return JNI_TRUE; } +ACR_IO_EXPORT_DECLARE(int, File, attrg0)(ACR_JNISTDARGS, jstring pathname) +{ +int attr = 0; + +UNREFERENCED_O; + +WITH_CSTR(pathname) { +char *sep; +int protection = ACR_FileProtectionGet(_E, J2S(pathname)); +if (protection = 0) { +if ((protection ACR_FPROT_UWRITE) != ACR_FPROT_UWRITE) +attr |= ACR_FILE_ATTR_READONLY; +if ((protection (ACR_FPROT_UEXECUTE | ACR_FPROT_GEXECUTE | ACR_FPROT_WEXECUTE))) +attr |= ACR_FILE_ATTR_EXECUTABLE; +} +if ((sep = strrchr(J2S(pathname), '/')) != NULL) { +/* Presume dot files are hidden + */ +if (*(sep + 1) == '.') +attr |= ACR_FILE_ATTR_HIDDEN; +} +else if (*J2S(pathname) == '.') +attr |= ACR_FILE_ATTR_HIDDEN; +} END_WITH_CSTR(pathname); + +return attr; +} + Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=789743r1=789742r2=789743view=diff == --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Tue Jun 30 14:08:24 2009 @@ -272,6 +272,42 @@ f.delete(); } +public void testGetAttributes() +throws Exception +{ +File f = new File(ffoo); +f.createNewFile(); +EnumSet FileProtection fp = f.getFileProtection(); +System.out.println(); +System.out.println(Org Rdonly Protection + fp); +// Set the rdonly attributes +f.setFileAttributes(EnumSet.of(FileAttributes.READONLY), EnumSet.allOf(FileAttributes.class)); +EnumSetFileAttributes fa = f.getFileAttributes(); +System.out.println(Get FileAttributes + fa); +assertTrue(READONLY, fa.contains(FileAttributes.READONLY)); +// Clear the
svn commit: r789753 - in /commons/sandbox/runtime/trunk/src/main/native/os: unix/file.c win32/file.c
Author: mturk Date: Tue Jun 30 14:17:11 2009 New Revision: 789753 URL: http://svn.apache.org/viewvc?rev=789753view=rev Log: Add getFileAttributes method Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=789753r1=789752r2=789753view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Tue Jun 30 14:17:11 2009 @@ -470,7 +470,7 @@ WITH_CSTR(pathname) { char *sep; int protection = ACR_FileProtectionGet(_E, J2S(pathname)); -if (protection = 0) { +if (protection 0) { if ((protection ACR_FPROT_UWRITE) != ACR_FPROT_UWRITE) attr |= ACR_FILE_ATTR_READONLY; if ((protection (ACR_FPROT_UEXECUTE | ACR_FPROT_GEXECUTE | ACR_FPROT_WEXECUTE))) Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=789753r1=789752r2=789753view=diff == --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Jun 30 14:17:11 2009 @@ -822,3 +822,39 @@ } return rv; } + +ACR_IO_EXPORT_DECLARE(int, File, attrg0)(ACR_JNISTDARGS, jstring pathname) +{ +int attr = 0; +int ex = 0; +DWORD flags; + +UNREFERENCED_O; + +WITH_WSTR(pathname) { +FS2BS(J2W(pathname)); +flags = GetFileAttributesW(J2W(pathname)); +if (flags != 0x) { +if ((flags FILE_ATTRIBUTE_HIDDEN)) +attr |= ACR_FILE_ATTR_HIDDEN; +if ((flags FILE_ATTRIBUTE_READONLY)) { +attr |= ACR_FILE_ATTR_READONLY; +if (!(flags FILE_ATTRIBUTE_HIDDEN)) +attr |= ACR_FILE_ATTR_EXECUTABLE; +} +} +else +ex = ACR_GET_OS_ERROR(); +} END_WITH_WSTR(pathname); + +if (ex) { +if (ACR_STATUS_IS_EACCES(ex)) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0); +} +else if (!ACR_STATUS_IS_EEXIST(ex)) { +ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex); +} +} +return attr; +} +