Exemplo n.º 1
0
            public String create(java.lang.Void using) {
              Logger.performance("Detecting MimeType", FileStream.this);
              String type =
                  detectedProbeContentType.read(
                      new SoftWriteReader<String, PropAccessor<Creator<String, File>>>() {
                        @Override
                        public String soft(PropAccessor<Creator<String, File>> data) {
                          return data.get().create(internal.get());
                        }

                        @Override
                        public String read(PropAccessor<Creator<String, File>> data) {
                          ClassLoader cl = ClassLoader.getSystemClassLoader();
                          try {
                            final Class<?> pathClass = cl.loadClass("java.nio.file.Path");
                            final Class<?> pathsClass = cl.loadClass("java.nio.file.Paths");
                            final Class<?> filesClass = cl.loadClass("java.nio.file.Files");

                            data.set(
                                new Creator<String, File>() {
                                  final Method pathsGet = pathsClass.getMethod("get", URI.class);
                                  final Method probeContentType =
                                      filesClass.getMethod("probeContentType", pathClass);

                                  {
                                    create(internal.get()); // Test it once
                                    Logger.debug(
                                        "Detected Java 7 APIs", pathsGet, probeContentType);
                                  }

                                  public String create(File using) {
                                    try {
                                      return (String)
                                          probeContentType.invoke(
                                              null, pathsGet.invoke(null, using.toURI()));
                                    } catch (IllegalAccessException ex) {
                                      return null;
                                    } catch (IllegalArgumentException ex) {
                                      return null;
                                    } catch (InvocationTargetException ex) {
                                      return null;
                                    }
                                  }
                                });
                          } catch (Throwable t) {
                            data.set(
                                new Creator<String, File>() {
                                  public String create(File using) {
                                    return null;
                                  }
                                });
                            Logger.exception(Logger.Level.Gears, t);
                          }

                          return data.get().create(internal.get());
                        }
                      });
              if (type == null) type = FileStream.super.mimeType();
              return type;
            }
Exemplo n.º 2
0
 public File create(java.lang.Void using) {
   Logger.performance("Reading file information", internalPath);
   return new File(internalPath);
 }
Exemplo n.º 3
0
 public FileStream create(String filePath) {
   Logger.performance("Opening FileStream", filePath);
   return new FileStream(filePath);
 }