Returns a string representing the proper path for this file. If this file path is absolute, the user.dir property is not prepended, otherwise it is. @param internal is user.dir internal. @return the proper path.
(boolean internal)
| 1333 | * @return the proper path. |
| 1334 | */ |
| 1335 | byte[] properPath(boolean internal) { |
| 1336 | if (properPath != null) { |
| 1337 | return properPath; |
| 1338 | } |
| 1339 | |
| 1340 | if (isAbsolute()) { |
| 1341 | byte[] pathBytes = Util.getUTF8Bytes(path); |
| 1342 | return properPath = pathBytes; |
| 1343 | } |
| 1344 | // Check security by getting user.dir when the path is not absolute |
| 1345 | String userdir; |
| 1346 | // if (internal) { |
| 1347 | // userdir = AccessController.doPrivileged(new PriviAction<String>( |
| 1348 | // "user.dir")); //$NON-NLS-1$ |
| 1349 | // } else { |
| 1350 | userdir = System.getProperty("user.dir"); //$NON-NLS-1$ |
| 1351 | // } |
| 1352 | |
| 1353 | if (path.length() == 0) { |
| 1354 | return properPath = Util.getUTF8Bytes(userdir); |
| 1355 | } |
| 1356 | int length = userdir.length(); |
| 1357 | |
| 1358 | // Handle windows-like path |
| 1359 | if (path.charAt(0) == '\\') { |
| 1360 | if (length > 1 && userdir.charAt(1) == ':') { |
| 1361 | return properPath = Util.getUTF8Bytes(userdir.substring(0, 2) |
| 1362 | + path); |
| 1363 | } |
| 1364 | path = path.substring(1); |
| 1365 | } |
| 1366 | |
| 1367 | // Handle separator |
| 1368 | String result = userdir; |
| 1369 | if (userdir.charAt(length - 1) != separatorChar) { |
| 1370 | if (path.charAt(0) != separatorChar) { |
| 1371 | result += separator; |
| 1372 | } |
| 1373 | } else if (path.charAt(0) == separatorChar) { |
| 1374 | result = result.substring(0, length - 2); |
| 1375 | |
| 1376 | } |
| 1377 | result += path; |
| 1378 | return properPath = Util.getUTF8Bytes(result); |
| 1379 | } |
| 1380 | |
| 1381 | /** |
| 1382 | * Renames this file to the name represented by the {@code dest} file. This |
no test coverage detected