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


Java Files.probeContentType方法代码示例

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


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

示例1: readMetdataFor

import java.nio.file.Files; //导入方法依赖的package包/类
public Metadata readMetdataFor(File f) throws JpegProcessingException {
  Metadata m = null;
  try {
      String mime = Files.probeContentType(f.toPath());
      System.out.println(mime);
      switch(mime){
          case "image/jpeg":
              m = JpegMetadataReader.readMetadata(f,readers);
              break;
          case "image/png":
              m = PngMetadataReader.readMetadata(f);
              break;
          case "image/gif":
              m = GifMetadataReader.readMetadata(f);
              break;
          case "image/bmp":
              m = BmpMetadataReader.readMetadata(f);
              break;
      }
  } catch (IOException | PngProcessingException ex) {
      Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  }
  return m;
}
 
开发者ID:Obsidiam,项目名称:joanne,代码行数:25,代码来源:ImageManager.java

示例2: read

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Reads the file
 * 
 * @param file The file
 * @return Image
 * @throws IOException Impossible read the file 
 */
public Image read(File file) throws IOException {
    String fileType = Files.probeContentType(file.toPath());
    if (isDicom(fileType) || file.getName().endsWith(".dcm")) {
        return readDicom(file);
    }
    return readImage(file);
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:15,代码来源:InputReader.java

示例3: invoke

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
Object invoke(final MinijaxRequestContext ctx) throws Exception {
    final String resourceName;

    if (directory) {
        resourceName = baseResourceName + "/" + ctx.getUriInfo().getPathParameters().getFirst("file");
    } else {
        resourceName = baseResourceName;
    }

    final URL resourceUrl = MinijaxStaticResource.class.getClassLoader().getResource(resourceName);
    if (resourceUrl == null) {
        return Response.status(Status.NOT_FOUND).build();
    }

    final File resourceFile = new File(resourceUrl.getFile());
    if (resourceFile.isDirectory()) {
        return Response.status(Status.NOT_FOUND).build();
    }

    final String contentType = Files.probeContentType(resourceFile.toPath());
    final MediaType mediaType = contentType == null ? MediaType.APPLICATION_OCTET_STREAM_TYPE : MediaType.valueOf(contentType);
    return Response.ok(resourceUrl.openStream(), mediaType).cacheControl(PUBLIC).build();
}
 
开发者ID:minijax,项目名称:minijax,代码行数:25,代码来源:MinijaxStaticResource.java

示例4: isValid

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isValid(File file, ConstraintValidatorContext context) {
    if(Optional.ofNullable(file).isPresent()) {
        String contentType;
        try {
            contentType = Files.probeContentType(file.toPath());
        } catch (IOException e) {
            throw new ResourcePreconditionException("An I/O error occurs");
        }
        return contentType.equals("image/png")
                || contentType.equals("image/jpeg");
    }

    return true;
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:16,代码来源:ImageValidator.java

示例5: validImage

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Convenience method of validation of an image file.
 *
 * @param file The file for validation
 * @throws ResourcePreconditionException if an I/O error occurs or incorrect content type
 */
public static void validImage(final File file) throws ResourcePreconditionException {
    String contentType;
    try {
        contentType = Files.probeContentType(file.toPath());
    } catch (IOException e) {
        throw new ResourcePreconditionException("An I/O error occurs");
    }
    if(!contentType.equals(PNG_MIME_TYPE)
            && !contentType.equals(JPEG_MIME_TYPE)) {
        throw new ResourcePreconditionException("Incorrect content type");
    }
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:19,代码来源:FileUtils.java

示例6: contentType

import java.nio.file.Files; //导入方法依赖的package包/类
public static final String contentType(String filename){
	String type = null;
	Path path = Paths.get(filename);
	try {
		type = Files.probeContentType(path);
	} catch (IOException e) {
		e.printStackTrace();
	}
	return type;
}
 
开发者ID:Anyfast-Team,项目名称:Anyfast-Java,代码行数:11,代码来源:FileAPI.java

示例7: probeFileTypes

import java.nio.file.Files; //导入方法依赖的package包/类
private static void probeFileTypes() throws Exception {		
	List<String> missmatches = new LinkedList<String>();		
	for (Path path: fileToMimeMap.keySet()) {
		System.out.print("Checking " + path + " ...\t");
		Path filename = rootDirectory.resolve(path);
		if (Files.notExists(filename)) {
			System.err.println(filename + " doesn't exist, unable to probe file type");
		} else {
			String fileType = Files.probeContentType(filename);
			String expectedFileType = fileToMimeMap.get(path);
			
			// The return value can be legitimately null if it doesn't know what it is
			// So skip the checking if it is, and carry on
			if (fileType != null) {
				if (!expectedFileType.equalsIgnoreCase(fileType)) {
					missmatches.add(path +"'s filetype was '" + fileType +  "' but we expected '" + expectedFileType + "'");
					System.out.println("Fail");
				} else {
					System.out.println("OK");
				}
			} else {
				System.out.println("Unknown");
			}
		}
	}
	
	if (missmatches.size() > 0) {
		for (String message: missmatches) {
			System.out.println(message);
		}
		// Wait until here to fail so that we can list all the failures, 
		//  rather than just the first one.
		fail(Arrays.toString(missmatches.toArray()));
	}		
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:36,代码来源:ProbeContentTypeTest.java

示例8: getFileInfo

import java.nio.file.Files; //导入方法依赖的package包/类
private FileInfo getFileInfo(File file) {
    String fileType = "";
    try {
        fileType =  Files.probeContentType(file.toPath());
    } catch (IOException e) {
        LOGGER.info("Can't get file type for file: " + file);
    }

    String url = this.getPathUrlFunction.apply(file.toPath());

    return new FileInfo(file.getName(), fileType, file.length(), Instant.ofEpochMilli(file.lastModified()), url);
}
 
开发者ID:chaokunyang,项目名称:amanda,代码行数:13,代码来源:FileSystemStorageService.java

示例9: postImage

import java.nio.file.Files; //导入方法依赖的package包/类
public static String postImage(String id, String url, File file,
                               String mediatype, Map<String, Object> uploadMediaRequest,
                               String passTicket) throws IOException {

    log.debug("local cookies: " + localCookie.toString());
    String webwxDataTicket = StringUtils.substringBetween(localCookie.toString(), "webwx_data_ticket=", "; expires");
    if (StringUtils.isBlank(webwxDataTicket)) {
        log.error("No webwx_data_ticket in cookies");
        return null;
    }

    String type = Files.probeContentType(file.toPath());

    RequestBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("id", id)
            .addFormDataPart("name", file.getName())
            .addFormDataPart("type", type)
            .addFormDataPart("lastModifiedDate", LocalDate.now().getMonthValue()
                    + "/" + LocalDate.now().getDayOfMonth()
                    + "/" + LocalDate.now().getYear()
                    + ", " + LocalTime.now().withNano(0)
                    + " GMT+0800 (CST)")
            .addFormDataPart("size", String.valueOf(Files.size(file.toPath())))
            .addFormDataPart("mediatype", mediatype)
            .addFormDataPart("uploadmediarequest", mapper.writeValueAsString(uploadMediaRequest))
            .addFormDataPart("webwx_data_ticket", webwxDataTicket)
            .addFormDataPart("pass_ticket", passTicket)
            .addFormDataPart("filename", file.getName(), RequestBody.create(MediaType.parse(type), file))
            .build();

    Request request = new Request.Builder()
            .addHeader(USER_AGENT, USER_AGENT_CONTENT)
            .url(url)
            .post(requestBody)
            .build();

    try (ResponseBody responseBody = client.newCall(request).execute().body()) {
        return responseBody.string();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ingbyr,项目名称:WechatBot,代码行数:45,代码来源:NetUtils.java


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