Search in sources :

Example 6 with FileNameMap

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;
}
Also used : FileNameMap(java.net.FileNameMap)

Example 7 with FileNameMap

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;
}
Also used : FileNameMap(java.net.FileNameMap)

Example 8 with FileNameMap

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;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileNameMap(java.net.FileNameMap)

Example 9 with FileNameMap

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;
}
Also used : FileNameMap(java.net.FileNameMap)

Example 10 with FileNameMap

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;
    }
}
Also used : FileNameMap(java.net.FileNameMap) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

FileNameMap (java.net.FileNameMap)34 File (java.io.File)7 SimpleDateFormat (java.text.SimpleDateFormat)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 DigestException (com.openmeap.digest.DigestException)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)2 BufferedInputStream (java.io.BufferedInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Map (java.util.Map)2 Wrong (app.hongs.util.verify.Wrong)1 Category (com.agiletec.aps.system.services.category.Category)1 BaseResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean)1 ModelManager (com.openmeap.model.ModelManager)1 Application (com.openmeap.model.dto.Application)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1