当前位置: 首页>>代码示例>>Java>>正文


Java MimetypesFileTypeMap.getContentType方法代码示例

本文整理汇总了Java中javax.activation.MimetypesFileTypeMap.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java MimetypesFileTypeMap.getContentType方法的具体用法?Java MimetypesFileTypeMap.getContentType怎么用?Java MimetypesFileTypeMap.getContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.activation.MimetypesFileTypeMap的用法示例。


在下文中一共展示了MimetypesFileTypeMap.getContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setContentTypeHeader

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Sets the content type header for the HTTP Response
 *
 * @param response
 *            HTTP response
 * @param file
 *            file to extract content type
 */
private static void setContentTypeHeader(HttpResponse response, String path) {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    ////////////////////////////////////////
    //NOTE: this does not work and behaves different between Java releases!!!!!
    ///////////////////////////////////////
    String contentType = mimeTypesMap.getContentType(path); 
    //patching mistake from the above broken code.
    if (path.endsWith("css")) {
        contentType = "text/css";
    } else if (path.endsWith("html")) {
        contentType = "text/html";
    } else if (path.endsWith("jpg")) {
        contentType = "image/jpeg";
    }
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
}
 
开发者ID:oci-pronghorn,项目名称:NettyStages,代码行数:25,代码来源:HttpStaticFileServerHandler.java

示例2: isImage

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Obtains a files MIME type and returns true if it is of type image
 * @param fileName
 * @param output
 * @return true if an image; false otherwise
 */
public static boolean isImage(String fileName, boolean output) {
	
	MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
	String mimeType = mimeTypesMap.getContentType(fileName);
	
	if(output){
		System.out.println("Validating input file...");
		System.out.println("File type: "+mimeType);
	}
	
	if(mimeType.startsWith("image")){
		return true;
	}else{
		
		if(output){
			System.out.println("Invalid file type input. Please enter an image");
		}
		
		return false;
	}
	
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:29,代码来源:CityLandscapeUtilities.java

示例3: setContentTypeHeader

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Sets the content type header for the HTTP Response
 *
 * @param response
 *            HTTP response
 * @param file
 *            file to extract content type
 */
private static void setContentTypeHeader(HttpResponse response, String path) {
  String contentType = null;

  if(path.endsWith(".css")) {
    contentType = "text/css";
  }
  else if(path.endsWith(".js")) {
    contentType = "application/javascript";
  }
  else if(path.endsWith(".html")) {
    contentType = "text/html";
  }
  else {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    contentType = mimeTypesMap.getContentType(path);
  }

  response.headers().set(CONTENT_TYPE, contentType);
}
 
开发者ID:camunda,项目名称:camunda-bpm-workbench,代码行数:28,代码来源:HttpClasspathServerHandler.java

示例4: getMIMEType

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Return the mimetype of the file depending of his extension and the mime.types file
 * 
 * @param strFilename
 *            the file name
 * @return the file mime type
 */
public static String getMIMEType( String strFilename )
{
    try
    {
        MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap( AppPathService.getWebAppPath( ) + File.separator + FILE_MIME_TYPE );

        return mimeTypeMap.getContentType( strFilename.toLowerCase( ) );
    }
    catch( IOException e )
    {
        AppLogService.error( e );

        return DEFAULT_MIME_TYPE;
    }
}
 
开发者ID:lutece-platform,项目名称:lutece-core,代码行数:23,代码来源:FileSystemUtil.java

示例5: getKnownContentTypes

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 *
 *
 * @return
 */
private String[] getKnownContentTypes() {
    List<String> knownContentTypes = new ArrayList<>();
    MimetypesFileTypeMap map = new MimetypesFileTypeMap();
    for (String supportedImageType : ImageIO.getReaderFileSuffixes()) {
        String name = String.format("a.%s", supportedImageType);
        String contentType = map.getContentType(name);
        if (!contentType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
            knownContentTypes.add(contentType);
        }
    }
    return knownContentTypes.toArray(new String[knownContentTypes.size()]);
}
 
开发者ID:caprica,项目名称:image-service,代码行数:18,代码来源:JaxrsImageService.java

示例6: isImage

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
public static boolean isImage(File image) {
    MimetypesFileTypeMap mimetypesFileTypeMap = new MimetypesFileTypeMap();
    mimetypesFileTypeMap.addMimeTypes("image png tif jpg jpeg bmp");

    String mimeType = mimetypesFileTypeMap.getContentType(image);
    String type = mimeType.split("/")[0];
    return type.equals("image");
}
 
开发者ID:kaladivo,项目名称:android-icon-generator,代码行数:9,代码来源:FileUtils.java

示例7: getMimeType

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Determines the mime type for the file given by its name.
 *
 * @param f
 *            the name of the file
 * @return the mime type of the given file
 */
public static String getMimeType(String f) {
    if (f == null) {
        return "application/octet-stream";
    }
    MimetypesFileTypeMap mTypes = new MimetypesFileTypeMap();
    return mTypes.getContentType(f.toLowerCase(Locale.ROOT));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRXMLFunctions.java

示例8: convertToSpreedSheet

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
public static boolean convertToSpreedSheet(Drive drive,
                                           String path) {
    com.google.api.services.drive.model.File fileMetaData = new com.google.api.services.drive.model.File();
    java.io.File file = new java.io.File(path);
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();

    fileMetaData.setName(file.getName());
    String googleSheetMimeType = "application/vnd.google-apps.spreadsheet";
    fileMetaData.setMimeType(googleSheetMimeType);

    FileContent mediaContent = new FileContent(mimeTypesMap.getContentType(file), file);

    com.google.api.services.drive.model.File f = null;
    Drive.Files.Create create = null;

    try {
        System.out.println("Uploading file " + file.getName());
        create = drive.files().create(fileMetaData, mediaContent)
                .setFields("id, parents, mimeType, webViewLink");
        create.getMediaHttpUploader().setProgressListener(new FileUpdateProgressListener());

        // Using default chunk size of 10MB.
        create.getMediaHttpUploader().setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE);
        f = create.execute();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    System.out.println("File ID: " + f.getId() + " Parent: " + f.getParents().toString()
    + " MimeType: " + f.getMimeType() + " link: " + f.getWebViewLink());
    return true;

}
 
开发者ID:atuljangra,项目名称:ExcelToGoogleSpreadSheet,代码行数:34,代码来源:SpreadSheet.java

示例9: getNext

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Fetches the next piece of content of type T and returns it. This method can be safely invoked until
 * complete() returns false. From which on this method will return null.
 *
 * @return Content of type T.
 */
@Override
public Mesh getNext() {
    try {
        MimetypesFileTypeMap filetypes = new MimetypesFileTypeMap("mime.types");
        String contenttype = filetypes.getContentType(this.inputFile.toFile());

        /* Try to detach decoder from the list of cached decoders. */
        Decoder<Mesh> decoder = this.cachedDecoders.get(contenttype);

        /* If decoder is null, create a new one. */
        if (decoder == null) {
          decoder = decoderForContenttype(contenttype);
        }

        /* If decoder is still null, return an emtpy Mesh. */
        if (decoder == null) {
            LOGGER.warn("Could not find mesh decoder for provided contenttype {}.", contenttype);
            return Mesh.EMPTY;
        } else {
            this.cachedDecoders.put(contenttype, decoder);
        }

        /* Initialize the decoder and return the decoded mesh. */
        decoder.init(this.inputFile, null);
        Mesh mesh = decoder.getNext();
        this.complete.set(true);
        return mesh;
    } catch (IOException e) {
        LOGGER.error("Could not decode mesh file {} due to an IO exception ({})", this.inputFile.toString(), LogHelper.getStackTrace(e));
        this.complete.set(true);
        return null;
    }
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:40,代码来源:ModularMeshDecoder.java

示例10: convert

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Converts a single file to a QueryContainer.
 *
 * @param path Path the file that should be converted.
 * @return QueryContainer for the specified file.
 */
@Override
public QueryContainer convert(Path path) {
    try {
        MimetypesFileTypeMap filetypes = new MimetypesFileTypeMap("mime.types");
        String contenttype = filetypes.getContentType(path.toFile());

        /* Try to detach decoder from the list of cached decoders. */
        Decoder<Mesh> decoder = this.cachedDecoders.get(contenttype);

        /* If decoder is null, create a new one. */
        if (decoder == null) {
          decoder = decoderForContenttype(contenttype);
        }

        /* If decoder is still null, return an emtpy Mesh. */
        if (decoder == null) {
            LOGGER.warn("Could not find mesh decoder for provided contenttype {}.", contenttype);
            return null;
        } else {
            this.cachedDecoders.put(contenttype, decoder);
        }

        /* Initialize the decoder and return the decoded mesh. */
        decoder.init(path, null);
        Mesh mesh = decoder.getNext();
        return new ModelQueryContainer(mesh);
    } catch (IOException e) {
        LOGGER.error("Could not decode mesh file {} due to an IO exception ({})", path.toString(), LogHelper.getStackTrace(e));
        return null;
    }
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:38,代码来源:ModularMeshDecoder.java

示例11: setContentTypeHeader

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * This will set the content types of files. If you want to support any
 * files add the content type and corresponding file extension here.
 *
 * @param response
 * @param file
 */
private static void setContentTypeHeader(HttpResponse response, File file) {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    mimeTypesMap.addMimeTypes("image png tif jpg jpeg bmp");
    mimeTypesMap.addMimeTypes("text/plain txt");
    mimeTypesMap.addMimeTypes("application/pdf pdf");

    String mimeType = mimeTypesMap.getContentType(file);

    response.headers().set(CONTENT_TYPE, mimeType);
}
 
开发者ID:classtag,项目名称:scratch_zookeeper_netty,代码行数:18,代码来源:HttpStaticFileServerHandler.java

示例12: makeContentResource

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
private ContentResource makeContentResource(String filename) {
 AttachmentHelper attachmentHelper = new AttachmentHelper();
 StringBuffer fullFilePath = new StringBuffer(unzipLocation);
 fullFilePath.append("/");
 fullFilePath.append(filename);
 MimetypesFileTypeMap mimetypesFileTypeMap = new MimetypesFileTypeMap();
 String contentType = mimetypesFileTypeMap.getContentType(filename);
 ContentResource contentResource = attachmentHelper.createContentResource(fullFilePath.toString(), filename, contentType);
 
 return contentResource;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:12,代码来源:ExtractionHelper.java

示例13: getIcon

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
@Override
public ResponseEntity<InputStreamResource> getIcon(String definitionName, DefinitionImageType imageType) {
    notNull(definitionName, "Definition name cannot be null.");
    notNull(imageType, "Definition image type cannot be null.");
    final Definition<?> definition = propertiesHelpers.getDefinition(definitionName);
    notNull(definition, "Could not find definition of name %s", definitionName);

    // Undefined and missing icon resources are simply 404.
    String imagePath = definition.getImagePath(imageType);
    if (imagePath == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    InputStream is = definition.getClass().getResourceAsStream(imagePath);
    if (is == null) {
        log.info("The image type %s should exist for %s at %s, but is missing. "
                + "The component should provide this resource.", imageType, definitionName, imagePath);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // At this point, we have enough information for a correct response.
    ResponseEntity.BodyBuilder response = ResponseEntity.ok();

    // Add the content type if it can be determined.
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    String contentType = mimeTypesMap.getContentType(imagePath);
    if (contentType != null) {
        response = response.contentType(MediaType.parseMediaType(contentType));
    }

    return response.body(new InputStreamResource(is));
}
 
开发者ID:Talend,项目名称:components,代码行数:32,代码来源:PropertiesControllerImpl.java

示例14: getMimetype

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
public String getMimetype(File inputFile) {
    try {
        return getMatch(inputFile).getMimeType();
    } catch (MagicMatchNotFoundException e) {
        LOGGER.debug("Failed to get Mime Type", e);
        final MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
        return mimeTypesMap.getContentType(inputFile);
    }
}
 
开发者ID:PhoenicisOrg,项目名称:POL-POM-5,代码行数:10,代码来源:FileAnalyser.java

示例15: getContentType

import javax.activation.MimetypesFileTypeMap; //导入方法依赖的package包/类
/**
 * Return the content-type of a file, according to it extension.
 * @param file the file.
 * @return the content-type.
 */
private static String getContentType(final File file) {
    final MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    final String contentType = mimeTypesMap.getContentType(file);
    if (contentType == null) {
        return "application/octet-stream";
    } else {
        return contentType;
    }
}
 
开发者ID:qjafcunuas,项目名称:jbromo,代码行数:15,代码来源:DownloadUtil.java


注:本文中的javax.activation.MimetypesFileTypeMap.getContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。