BrightSide Workbench Full Report + Source Code
org.turro.upload.Medias Class Reference

Static Public Member Functions

static void toFolder (Media media, Folder folder)
 
static void toFolder (Media media, Folder folder, Consumer< File > consumer)
 
static void toFolder (Media media, File folder)
 
static void toFolder (Media media, File folder, Consumer< File > consumer)
 
static void toFile (Media media, File file)
 
static void toFile (Media media, File file, Consumer< File > consumer)
 
static Reader toReader (Media media)
 
static InputStream toStream (Media media)
 
static Consumer< File > scaling (double scale)
 
static Consumer< File > smart (double width, double height)
 
static Consumer< File > standard ()
 
static Function< File, Boolean > smaller (long size)
 

Static Public Attributes

static final long MAX_FILE_SIZE = BytesFormatter.parseBytes("16MB")
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 46 of file Medias.java.

Member Function Documentation

◆ scaling()

static Consumer<File> org.turro.upload.Medias.scaling ( double  scale)
static

Definition at line 102 of file Medias.java.

102  {
103  return (file) -> {
104  try {
105  ImageUtil.scale(file, file, scale);
106  } catch (IOException ex) {
107  Toasts.message(I_.get("Bad format image")).show();
108  file.delete();
109  Logger.getLogger(Medias.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
110  }
111  };
112  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ smaller()

static Function<File, Boolean> org.turro.upload.Medias.smaller ( long  size)
static

Definition at line 142 of file Medias.java.

142  {
143  return (file) -> {
144  if(file.length() > size) {
145  Toasts.message(I_.get("File is too large")).show();
146  file.delete();
147  return false;
148  }
149  return true;
150  };
151  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ smart()

static Consumer<File> org.turro.upload.Medias.smart ( double  width,
double  height 
)
static

Definition at line 114 of file Medias.java.

114  {
115  return (file) -> {
116  try {
117  ImageUtil.smart(file, file, width, height);
118  } catch (IOException ex) {
119  Toasts.message(I_.get("Bad format image")).show();
120  file.delete();
121  Logger.getLogger(Medias.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
122  }
123  };
124  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ standard()

static Consumer<File> org.turro.upload.Medias.standard ( )
static

Definition at line 126 of file Medias.java.

126  {
127  return (file) -> {
128  if(Document.from(file).isImage()) {
129  try {
130  ImageUtil.scale(file, file, 1200);
131  } catch (IOException ex) {
132  Toasts.message(I_.get("Bad format image")).show();
133  file.delete();
134  Logger.getLogger(Medias.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
135  }
136  } else {
137  smaller(MAX_FILE_SIZE).apply(file);
138  }
139  };
140  }
static final long MAX_FILE_SIZE
Definition: Medias.java:48
static Function< File, Boolean > smaller(long size)
Definition: Medias.java:142
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFile() [1/2]

static void org.turro.upload.Medias.toFile ( Media  media,
File  file 
)
static

Definition at line 66 of file Medias.java.

66  {
67  toFile(media, file, standard());
68  }
static void toFile(Media media, File file)
Definition: Medias.java:66
static Consumer< File > standard()
Definition: Medias.java:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFile() [2/2]

static void org.turro.upload.Medias.toFile ( Media  media,
File  file,
Consumer< File >  consumer 
)
static

Definition at line 70 of file Medias.java.

70  {
71  try(FileOutputStream fos = new FileOutputStream(file)) {
72  if(media.inMemory()) {
73  fos.write(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
74  } else {
75  byte[] buffer = new byte[102400];
76  try(InputStream is = toStream(media)) {
77  int r;
78  while((r = is.read(buffer)) != -1) {
79  fos.write(buffer, 0, r);
80  }
81  }
82  }
83  } catch (IOException ex) {
84  Logger.getLogger(RepositoryContent.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
85  }
86  if(file.exists() && consumer != null) {
87  consumer.accept(file);
88  }
89  }
static InputStream toStream(Media media)
Definition: Medias.java:98
Here is the call graph for this function:

◆ toFolder() [1/4]

static void org.turro.upload.Medias.toFolder ( Media  media,
File  folder 
)
static

Definition at line 58 of file Medias.java.

58  {
59  toFolder(media, folder, standard());
60  }
static void toFolder(Media media, Folder folder)
Definition: Medias.java:50
Here is the call graph for this function:

◆ toFolder() [2/4]

static void org.turro.upload.Medias.toFolder ( Media  media,
File  folder,
Consumer< File >  consumer 
)
static

Definition at line 62 of file Medias.java.

62  {
63  toFile(media, Folder.from(folder).ensure().path().resolve(Document.correctName(media.getName())).toFile(), consumer);
64  }
Here is the call graph for this function:

◆ toFolder() [3/4]

static void org.turro.upload.Medias.toFolder ( Media  media,
Folder  folder 
)
static

Definition at line 50 of file Medias.java.

50  {
51  toFolder(media, folder, standard());
52  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFolder() [4/4]

static void org.turro.upload.Medias.toFolder ( Media  media,
Folder  folder,
Consumer< File >  consumer 
)
static

Definition at line 54 of file Medias.java.

54  {
55  toFolder(media, folder.folder(), consumer);
56  }
Here is the call graph for this function:

◆ toReader()

static Reader org.turro.upload.Medias.toReader ( Media  media)
static

Definition at line 91 of file Medias.java.

91  {
92  if(!media.isBinary()) {
93  return media.getReaderData();
94  }
95  return null;
96  }
Here is the caller graph for this function:

◆ toStream()

static InputStream org.turro.upload.Medias.toStream ( Media  media)
static

Definition at line 98 of file Medias.java.

98  {
99  return media.isBinary() ? media.getStreamData() : new ReaderInputStream(media.getReaderData(), Charset.defaultCharset());
100  }
Here is the caller graph for this function:

Member Data Documentation

◆ MAX_FILE_SIZE

final long org.turro.upload.Medias.MAX_FILE_SIZE = BytesFormatter.parseBytes("16MB")
static

Definition at line 48 of file Medias.java.


The documentation for this class was generated from the following file: