324 */
325 private void decodePath(String path) {
326 int i = path.indexOf(";type=");
327 if (i >= 0) {
328 String s1 = path.substring(i + 6, path.length());
329 if ("i".equalsIgnoreCase(s1)) {
330 type = BIN;
331 }
332 if ("a".equalsIgnoreCase(s1)) {
333 type = ASCII;
334 }
335 if ("d".equalsIgnoreCase(s1)) {
336 type = DIR;
337 }
338 path = path.substring(0, i);
339 }
340 if (path != null && path.length() > 1 &&
341 path.charAt(0) == '/') {
342 path = path.substring(1);
343 }
344 if (path == null || path.length() == 0) {
345 path = "./";
346 }
347 if (!path.endsWith("/")) {
348 i = path.lastIndexOf('/');
349 if (i > 0) {
350 filename = path.substring(i + 1, path.length());
351 filename = ParseUtil.decode(filename);
352 pathname = path.substring(0, i);
353 } else {
354 filename = ParseUtil.decode(path);
355 pathname = null;
356 }
357 } else {
358 pathname = path.substring(0, path.length() - 1);
359 filename = null;
360 }
361 if (pathname != null) {
362 fullpath = pathname + "/" + (filename != null ? filename : "");
363 } else {
364 fullpath = filename;
538 connect();
539 }
540
541 if (http != null) {
542 OutputStream out = http.getOutputStream();
543 // getInputStream() is neccessary to force a writeRequests()
544 // on the http client.
545 http.getInputStream();
546 return out;
547 }
548
549 if (is != null) {
550 throw new IOException("Already opened for input");
551 }
552
553 if (os != null) {
554 return os;
555 }
556
557 decodePath(url.getPath());
558 if (filename == null || filename.length() == 0) {
559 throw new IOException("illegal filename for a PUT");
560 }
561 try {
562 if (pathname != null) {
563 cd(pathname);
564 }
565 if (type == ASCII) {
566 ftp.setAsciiType();
567 } else {
568 ftp.setBinaryType();
569 }
570 os = new FtpOutputStream(ftp, ftp.putFileStream(filename, false));
571 } catch (FtpProtocolException e) {
572 throw new IOException(e);
573 }
574 return os;
575 }
576
577 String guessContentTypeFromFilename(String fname) {
578 return guessContentTypeFromName(fname);
|
324 */
325 private void decodePath(String path) {
326 int i = path.indexOf(";type=");
327 if (i >= 0) {
328 String s1 = path.substring(i + 6, path.length());
329 if ("i".equalsIgnoreCase(s1)) {
330 type = BIN;
331 }
332 if ("a".equalsIgnoreCase(s1)) {
333 type = ASCII;
334 }
335 if ("d".equalsIgnoreCase(s1)) {
336 type = DIR;
337 }
338 path = path.substring(0, i);
339 }
340 if (path != null && path.length() > 1 &&
341 path.charAt(0) == '/') {
342 path = path.substring(1);
343 }
344 if (path == null || path.isEmpty()) {
345 path = "./";
346 }
347 if (!path.endsWith("/")) {
348 i = path.lastIndexOf('/');
349 if (i > 0) {
350 filename = path.substring(i + 1, path.length());
351 filename = ParseUtil.decode(filename);
352 pathname = path.substring(0, i);
353 } else {
354 filename = ParseUtil.decode(path);
355 pathname = null;
356 }
357 } else {
358 pathname = path.substring(0, path.length() - 1);
359 filename = null;
360 }
361 if (pathname != null) {
362 fullpath = pathname + "/" + (filename != null ? filename : "");
363 } else {
364 fullpath = filename;
538 connect();
539 }
540
541 if (http != null) {
542 OutputStream out = http.getOutputStream();
543 // getInputStream() is neccessary to force a writeRequests()
544 // on the http client.
545 http.getInputStream();
546 return out;
547 }
548
549 if (is != null) {
550 throw new IOException("Already opened for input");
551 }
552
553 if (os != null) {
554 return os;
555 }
556
557 decodePath(url.getPath());
558 if (filename == null || filename.isEmpty()) {
559 throw new IOException("illegal filename for a PUT");
560 }
561 try {
562 if (pathname != null) {
563 cd(pathname);
564 }
565 if (type == ASCII) {
566 ftp.setAsciiType();
567 } else {
568 ftp.setBinaryType();
569 }
570 os = new FtpOutputStream(ftp, ftp.putFileStream(filename, false));
571 } catch (FtpProtocolException e) {
572 throw new IOException(e);
573 }
574 return os;
575 }
576
577 String guessContentTypeFromFilename(String fname) {
578 return guessContentTypeFromName(fname);
|