use of java.net.FileNameMap in project jdk8u_jdk by JetBrains.
the class FileURLConnection method getInputStream.
public synchronized InputStream getInputStream() throws IOException {
int iconHeight;
int iconWidth;
connect();
if (is == null) {
if (isDirectory) {
FileNameMap map = java.net.URLConnection.getFileNameMap();
StringBuffer buf = new StringBuffer();
if (files == null) {
throw new FileNotFoundException(filename);
}
Collections.sort(files, Collator.getInstance());
for (int i = 0; i < files.size(); i++) {
String fileName = files.get(i);
buf.append(fileName);
buf.append("\n");
}
// Put it into a (default) locale-specific byte-stream.
is = new ByteArrayInputStream(buf.toString().getBytes());
} else {
throw new FileNotFoundException(filename);
}
}
return is;
}
use of java.net.FileNameMap in project portal by ixinportal.
the class OkHttpClientManagerPdfVerify method guessMimeType.
// ****************************
// private Request buildMultipartFormRequest(String url, File[] files,
// String[] fileKeys, Param[] params)
// {
// // params = validateParam(params);
//
// MultipartBody.Builder builder = new MultipartBody.Builder()
// .setType(MultipartBody.FORM);
//
// for (Param param : params)
// {
// builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
// RequestBody.create(null, param.value));
// }
// if (files != null)
// {
// RequestBody fileBody = null;
// for (int i = 0; i < files.length; i++)
// {
// File file = files[i];
// String fileName = file.getName();
// fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
// //TODO 根据文件名设置contentType
// builder.addPart(Headers.of("Content-Disposition",
// "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
// fileBody);
// }
// }
//
// RequestBody requestBody = builder.build();
// return new Request.Builder()
// .url(url)
// .post(requestBody)
// .build();
// }
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
use of java.net.FileNameMap in project YhLibraryForAndroid by android-coco.
the class PostFormRequest method guessMimeType.
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = null;
try {
contentTypeFor = fileNameMap.getContentTypeFor(URLEncoder.encode(path, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
use of java.net.FileNameMap in project Bytecoder by mirkosertic.
the class FileURLConnection method getInputStream.
public synchronized InputStream getInputStream() throws IOException {
int iconHeight;
int iconWidth;
connect();
if (is == null) {
if (isDirectory) {
FileNameMap map = java.net.URLConnection.getFileNameMap();
StringBuilder sb = new StringBuilder();
if (files == null) {
throw new FileNotFoundException(filename);
}
Collections.sort(files, Collator.getInstance());
for (int i = 0; i < files.size(); i++) {
String fileName = files.get(i);
sb.append(fileName);
sb.append("\n");
}
// Put it into a (default) locale-specific byte-stream.
is = new ByteArrayInputStream(sb.toString().getBytes());
} else {
throw new FileNotFoundException(filename);
}
}
return is;
}
use of java.net.FileNameMap in project j2objc by google.
the class FileURLConnection method initializeHeaders.
private void initializeHeaders() {
try {
connect();
exists = file.exists();
} catch (IOException e) {
}
if (!initializedHeaders || !exists) {
length = file.length();
lastModified = file.lastModified();
if (!isDirectory) {
FileNameMap map = java.net.URLConnection.getFileNameMap();
contentType = map.getContentTypeFor(filename);
if (contentType != null) {
properties.add(CONTENT_TYPE, contentType);
}
properties.add(CONTENT_LENGTH, String.valueOf(length));
/*
* Format the last-modified field into the preferred
* Internet standard - ie: fixed-length subset of that
* defined by RFC 1123
*/
if (lastModified != 0) {
Date date = new Date(lastModified);
SimpleDateFormat fo = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
fo.setTimeZone(TimeZone.getTimeZone("GMT"));
properties.add(LAST_MODIFIED, fo.format(date));
}
} else {
properties.add(CONTENT_TYPE, TEXT_PLAIN);
}
initializedHeaders = true;
}
}
Aggregations