View Javadoc
1   /*
2    * Copyright (C) 2012 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.geometry.io;
17  
18  import com.irurueta.geometry.InhomogeneousPoint3D;
19  import com.irurueta.geometry.Point3D;
20  import com.irurueta.geometry.Triangulator3D;
21  import com.irurueta.geometry.TriangulatorException;
22  
23  import java.io.File;
24  import java.io.IOException;
25  import java.nio.BufferUnderflowException;
26  import java.nio.ByteBuffer;
27  import java.util.ArrayList;
28  import java.util.List;
29  import java.util.TreeMap;
30  
31  /**
32   * Loads PLY files.
33   * This class is meant to read PLY files using an iterative process to read
34   * the file in small pieces of data.
35   * Because the file is loaded in small pieces, this class has a low memory
36   * impact. Besides parameters such as maxVerticesInChunk or maxStreamPositions
37   * can be adjusted in order to increase or reduce memory usage at the expense of
38   * performance (the greater the memory usage the better the performance).
39   * This class needs random access to file positions, and for that reason it
40   * cannot be used with streams.
41   * This class is based in the work of:
42   * <a href="http://w3.impa.br/~diego/software/rply/">http://w3.impa.br/~diego/software/rply/</a>
43   */
44  public class LoaderPLY extends Loader {
45      /**
46       * Size of internal buffer where bytes from stream of data read into.
47       * This size (8 bytes) is meant to be able to fit any data type.
48       *
49       * @see DataTypePLY
50       */
51      public static final int BUFFER_SIZE = 8;
52  
53      /**
54       * Constant defining maximum number of vertices to be stored in a single
55       * data chunk.
56       * By default, this is the maximum values stored in a short 65535. This is
57       * so that data chunks can be compatible with technologies such as openGL
58       * where vertex indices are short values, and hence only 65535 vertices can
59       * be indexed at a time.
60       */
61      public static final int DEFAULT_MAX_VERTICES_IN_CHUNK = 0xffff;
62  
63      /**
64       * Minimum allowed value for maximum vertices in a chunk. At least one
65       * vertex must be contained on a data chunk, for that reason this constant
66       * is 1.
67       */
68      public static final int MIN_MAX_VERTICES_IN_CHUNK = 1;
69  
70      /**
71       * Constant defining if by default duplicate vertices are allowed in a data
72       * chunk. By allowing duplicate vertices, PLY loading can be speed up a
73       * little bit at the expense of getting larger sets of data which will
74       * contain redundant vertices. If your environment is memory constrained,
75       * this should be disabled. By default, it is disabled.
76       */
77      public static final boolean DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK = false;
78  
79      /**
80       * Constant defining default maximum number of stream positions to be
81       * cached.
82       * This loader keeps track of a set of stream positions that have been
83       * parsed on ASCII mode. By keeping a cache of positions loading times can
84       * be largely reduced at the expense of using more memory during loading.
85       * By default, this is set to 1000000 positions.
86       * This only has effect on ASCII PLY files. For binary PLY files this
87       * constant is ignored.
88       */
89      public static final int DEFAULT_MAX_STREAM_POSITIONS = 1000000;
90  
91      /**
92       * Constant defining minimum allowed value for maximum stream positions.
93       */
94      public static final int MIN_STREAM_POSITIONS = 1;
95  
96      /**
97       * Constant defining when progress change should be notified. When progress
98       * is increased by this value from previous notification, then progress will
99       * be notified again.
100      */
101     public static final float PROGRESS_DELTA = 0.01f;
102 
103     /**
104      * Keeps PLY header data.
105      */
106     private HeaderPLY header;
107 
108     /**
109      * Boolean indicating if file is a valid PLY stream of data.
110      */
111     private boolean validStream;
112 
113     /**
114      * Boolean indicating whether validity of file has already been checked.
115      */
116     private boolean validityChecked;
117 
118     /**
119      * Iterator currently loading provided file.
120      */
121     private LoaderIteratorPLY loaderIterator;
122 
123     /**
124      * Indicates maximum number of vertices to keep in a chunk of data.
125      * By default, this is the maximum values stored in a short 65535. This is
126      * so that data chunks can be compatible with technologies such as openGL
127      * where vertex indices are short values, and hence only 65535 vertices can
128      * be indexed at a time.
129      */
130     private int maxVerticesInChunk;
131 
132     /**
133      * Indicates whether duplicate vertices in a chunk are allowed. By allowing
134      * duplicate vertices, PLY loading can be speed up a little bit at the
135      * expense of getting larger sets of data which will contain redundant
136      * vertices. If your environment is memory constrained, this should be
137      * disabled. By default, it is disabled.
138      */
139     private boolean allowDuplicateVerticesInChunk;
140 
141     /**
142      * Maximum number of stream positions to be cached.
143      * This loader keeps track of a set of stream positions that have been
144      * parsed on ASCII mode. By keeping a cache of positions loading times can
145      * be largely reduced at the expense of using more memory during loading.
146      * By default, this is set to 1000000 positions.
147      * This only has effect on ASCII PLY files. For binary PLY files this
148      * setting is ignored.
149      */
150     private long maxStreamPositions;
151 
152     /**
153      * Constructor.
154      */
155     public LoaderPLY() {
156         reader = null;
157         header = null;
158         validStream = false;
159         validityChecked = false;
160         loaderIterator = null;
161         maxVerticesInChunk = DEFAULT_MAX_VERTICES_IN_CHUNK;
162         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
163         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
164     }
165 
166     /**
167      * Constructor.
168      *
169      * @param maxVerticesInChunk Indicates maximum number of vertices to keep in
170      *                           a chunk of data.
171      * @throws IllegalArgumentException Raised if maximum number of vertices is
172      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
173      */
174     public LoaderPLY(final int maxVerticesInChunk) {
175         reader = null;
176         header = null;
177         validStream = false;
178         validityChecked = false;
179         loaderIterator = null;
180         internalSetMaxVerticesInChunk(maxVerticesInChunk);
181         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
182         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
183     }
184 
185     /**
186      * Constructor.
187      *
188      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
189      *                                      a chunk of data.
190      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
191      *                                      in a chunk are allowed.
192      * @throws IllegalArgumentException Raised if maximum number of vertices is
193      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
194      */
195     public LoaderPLY(final int maxVerticesInChunk, final boolean allowDuplicateVerticesInChunk) {
196         reader = null;
197         header = null;
198         validStream = false;
199         validityChecked = false;
200         loaderIterator = null;
201         internalSetMaxVerticesInChunk(maxVerticesInChunk);
202         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
203         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
204     }
205 
206     /**
207      * Constructor.
208      *
209      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
210      *                                      a chunk of data.
211      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
212      *                                      in a chunk are allowed.
213      * @param maxStreamPositions            Maximum number of stream positions to be
214      *                                      cached.
215      * @throws IllegalArgumentException Raised if maximum number of vertices is
216      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK or if maximum stream positions is
217      *                                  smaller than MIN_STREAM_POSITIONS.
218      */
219     public LoaderPLY(final int maxVerticesInChunk, final boolean allowDuplicateVerticesInChunk,
220                      final long maxStreamPositions) {
221         reader = null;
222         header = null;
223         validStream = false;
224         validityChecked = false;
225         loaderIterator = null;
226         internalSetMaxVerticesInChunk(maxVerticesInChunk);
227         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
228         internalSetMaxStreamPositions(maxStreamPositions);
229     }
230 
231     /**
232      * Constructor.
233      *
234      * @param f file to be loaded.
235      * @throws IOException if file does not exist or cannot be loaded.
236      */
237     public LoaderPLY(final File f) throws IOException {
238         super(f);
239         header = null;
240         validStream = false;
241         validityChecked = false;
242         loaderIterator = null;
243         maxVerticesInChunk = DEFAULT_MAX_VERTICES_IN_CHUNK;
244         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
245         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
246     }
247 
248     /**
249      * Constructor.
250      *
251      * @param f                  file to be loaded.
252      * @param maxVerticesInChunk Indicates maximum number of vertices to keep in
253      *                           a chunk of data.
254      * @throws IllegalArgumentException Raised if maximum number of vertices is
255      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
256      * @throws IOException              if file does not exist or cannot be loaded.
257      */
258     public LoaderPLY(final File f, final int maxVerticesInChunk) throws IOException {
259         super(f);
260         header = null;
261         validStream = false;
262         validityChecked = false;
263         loaderIterator = null;
264         internalSetMaxVerticesInChunk(maxVerticesInChunk);
265         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
266         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
267     }
268 
269     /**
270      * Constructor.
271      *
272      * @param f                             file to be loaded.
273      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
274      *                                      a chunk of data.
275      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
276      *                                      in a chunk are allowed.
277      * @throws IllegalArgumentException Raised if maximum number of vertices is
278      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
279      * @throws IOException              if file does not exist or cannot be loaded.
280      */
281     public LoaderPLY(final File f, final int maxVerticesInChunk, final boolean allowDuplicateVerticesInChunk)
282             throws IOException {
283         super(f);
284         header = null;
285         validStream = false;
286         validityChecked = false;
287         loaderIterator = null;
288         internalSetMaxVerticesInChunk(maxVerticesInChunk);
289         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
290         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
291     }
292 
293     /**
294      * Constructor.
295      *
296      * @param f                             file to be loaded.
297      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
298      *                                      a chunk of data.
299      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
300      *                                      in a chunk are allowed.
301      * @param maxStreamPositions            Maximum number of stream positions to be
302      *                                      cached.
303      * @throws IllegalArgumentException Raised if maximum number of vertices is
304      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK or if maximum stream positions is
305      *                                  smaller than MIN_STREAM_POSITIONS.
306      * @throws IOException              if file does not exist or cannot be loaded.
307      */
308     public LoaderPLY(final File f, final int maxVerticesInChunk, final boolean allowDuplicateVerticesInChunk,
309                      final long maxStreamPositions) throws IOException {
310         super(f);
311         header = null;
312         validStream = false;
313         validityChecked = false;
314         loaderIterator = null;
315         internalSetMaxVerticesInChunk(maxVerticesInChunk);
316         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
317         internalSetMaxStreamPositions(maxStreamPositions);
318     }
319 
320     /**
321      * Constructor.
322      *
323      * @param listener listener to notify start, end and progress events.
324      */
325     public LoaderPLY(final LoaderListener listener) {
326         super(listener);
327         reader = null;
328         header = null;
329         validStream = false;
330         validityChecked = false;
331         loaderIterator = null;
332         maxVerticesInChunk = DEFAULT_MAX_VERTICES_IN_CHUNK;
333         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
334         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
335     }
336 
337     /**
338      * Constructor.
339      *
340      * @param listener           listener to notify start, end and progress events.
341      * @param maxVerticesInChunk Indicates maximum number of vertices to keep in
342      *                           a chunk of data.
343      * @throws IllegalArgumentException Raised if maximum number of vertices is
344      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
345      */
346     public LoaderPLY(final LoaderListener listener, final int maxVerticesInChunk) {
347         super(listener);
348         reader = null;
349         header = null;
350         validStream = false;
351         validityChecked = false;
352         loaderIterator = null;
353         internalSetMaxVerticesInChunk(maxVerticesInChunk);
354         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
355         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
356     }
357 
358     /**
359      * Constructor.
360      *
361      * @param listener                      listener to notify start, end and progress events.
362      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
363      *                                      a chunk of data.
364      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
365      *                                      in a chunk are allowed.
366      * @throws IllegalArgumentException Raised if maximum number of vertices is
367      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
368      */
369     public LoaderPLY(final LoaderListener listener, final int maxVerticesInChunk,
370                      final boolean allowDuplicateVerticesInChunk) {
371         super(listener);
372         reader = null;
373         header = null;
374         validStream = false;
375         validityChecked = false;
376         loaderIterator = null;
377         internalSetMaxVerticesInChunk(maxVerticesInChunk);
378         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
379         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
380     }
381 
382     /**
383      * Constructor.
384      *
385      * @param listener                      listener to notify start, end and progress events.
386      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
387      *                                      a chunk of data.
388      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
389      *                                      in a chunk are allowed.
390      * @param maxStreamPositions            Maximum number of stream positions to be
391      *                                      cached.
392      * @throws IllegalArgumentException Raised if maximum number of vertices is
393      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK or if maximum stream positions is
394      *                                  smaller than MIN_STREAM_POSITIONS.
395      */
396     public LoaderPLY(final LoaderListener listener, final int maxVerticesInChunk,
397                      final boolean allowDuplicateVerticesInChunk, final long maxStreamPositions) {
398         super(listener);
399         reader = null;
400         header = null;
401         validStream = false;
402         validityChecked = false;
403         loaderIterator = null;
404         internalSetMaxVerticesInChunk(maxVerticesInChunk);
405         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
406         internalSetMaxStreamPositions(maxStreamPositions);
407     }
408 
409     /**
410      * Constructor.
411      *
412      * @param f        file to be loaded.
413      * @param listener listener to notify start, end and progress events.
414      * @throws IOException if file does not exist or cannot be loaded.
415      */
416     public LoaderPLY(final File f, final LoaderListener listener) throws IOException {
417         super(f, listener);
418         header = null;
419         validStream = false;
420         validityChecked = false;
421         loaderIterator = null;
422         maxVerticesInChunk = DEFAULT_MAX_VERTICES_IN_CHUNK;
423         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
424         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
425     }
426 
427     /**
428      * Constructor.
429      *
430      * @param f                  file to be loaded.
431      * @param listener           listener to notify start, end and progress events.
432      * @param maxVerticesInChunk Indicates maximum number of vertices to keep in
433      *                           a chunk of data.
434      * @throws IllegalArgumentException Raised if maximum number of vertices is
435      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
436      * @throws IOException              if file does not exist or cannot be loaded.
437      */
438     public LoaderPLY(final File f, final LoaderListener listener, final int maxVerticesInChunk) throws IOException {
439         super(f, listener);
440         header = null;
441         validStream = false;
442         validityChecked = false;
443         loaderIterator = null;
444         internalSetMaxVerticesInChunk(maxVerticesInChunk);
445         allowDuplicateVerticesInChunk = DEFAULT_ALLOW_DUPLICATE_VERTICES_IN_CHUNK;
446         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
447     }
448 
449     /**
450      * Constructor.
451      *
452      * @param f                             file to be loaded.
453      * @param listener                      listener to notify start, end and progress events.
454      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
455      *                                      a chunk of data.
456      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
457      *                                      in a chunk are allowed.
458      * @throws IllegalArgumentException Raised if maximum number of vertices is
459      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
460      * @throws IOException              if file does not exist or cannot be loaded.
461      */
462     public LoaderPLY(final File f, final LoaderListener listener, final int maxVerticesInChunk,
463                      final boolean allowDuplicateVerticesInChunk) throws IOException {
464         super(f, listener);
465         header = null;
466         validStream = false;
467         validityChecked = false;
468         loaderIterator = null;
469         internalSetMaxVerticesInChunk(maxVerticesInChunk);
470         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
471         maxStreamPositions = DEFAULT_MAX_STREAM_POSITIONS;
472     }
473 
474     /**
475      * Constructor.
476      *
477      * @param f                             file to be loaded.
478      * @param listener                      listener to notify start, end and progress events.
479      * @param maxVerticesInChunk            Indicates maximum number of vertices to keep in
480      *                                      a chunk of data.
481      * @param allowDuplicateVerticesInChunk Indicates whether duplicate vertices
482      *                                      in a chunk are allowed.
483      * @param maxStreamPositions            Maximum number of stream positions to be
484      *                                      cached.
485      * @throws IllegalArgumentException Raised if maximum number of vertices is
486      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK or if maximum stream positions is
487      *                                  smaller than MIN_STREAM_POSITIONS.
488      * @throws IOException              if file does not exist or cannot be loaded.
489      */
490     public LoaderPLY(final File f, final LoaderListener listener, final int maxVerticesInChunk,
491                      final boolean allowDuplicateVerticesInChunk, final long maxStreamPositions) throws IOException {
492         super(f, listener);
493         header = null;
494         validStream = false;
495         validityChecked = false;
496         loaderIterator = null;
497         internalSetMaxVerticesInChunk(maxVerticesInChunk);
498         internalSetAllowDuplicateVerticesInChunk(allowDuplicateVerticesInChunk);
499         internalSetMaxStreamPositions(maxStreamPositions);
500     }
501 
502     /**
503      * Returns maximum number of vertices to keep in a chunk of data.
504      * By default, this is the maximum values stored in a short is 65535. This is
505      * so that data chunks can be compatible with technologies such as openGL
506      * where vertex indices are short values, and hence only 65535 vertices can
507      * be indexed at a time.
508      *
509      * @return Maximum number of vertices to keep in a chunk of data.
510      */
511     public int getMaxVerticesInChunk() {
512         return maxVerticesInChunk;
513     }
514 
515     /**
516      * Sets maximum number of vertices to keep in a chunk of data.
517      *
518      * @param maxVerticesInChunk Indicates maximum number of vertices to keep in
519      *                           a chunk of data.
520      * @throws IllegalArgumentException Raised if maximum number of vertices is
521      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
522      * @throws LockedException          Raised if this instance is locked because loading
523      *                                  is in progress.
524      */
525     public void setMaxVerticesInChunk(final int maxVerticesInChunk) throws LockedException {
526         if (isLocked()) {
527             throw new LockedException();
528         }
529         internalSetMaxVerticesInChunk(maxVerticesInChunk);
530     }
531 
532     /**
533      * Determines whether duplicate vertices in a chunk are allowed. By allowing
534      * duplicate vertices, PLY loading can be speed up a little bit at the
535      * expense of getting larger sets of data which will contain redundant
536      * vertices. If your environment is memory constrained, this should be
537      * disabled. By default, it is disabled.
538      *
539      * @return Determines whether duplicate vertices in a chunk are allowed.
540      */
541     public boolean areDuplicateVerticesInChunkAllowed() {
542         return allowDuplicateVerticesInChunk;
543     }
544 
545     /**
546      * Sets whether duplicate vertices in a chunk are allowed. By allowing
547      * duplicate vertices, PLY loading can be speed up a little bit at the
548      * expense of getting larger sets of data which will contain redundant
549      * vertices. If your environment is memory constrained, this should be
550      * disabled. By default, it is disabled.
551      *
552      * @param allow Indicates whether duplicates will be allowed or not.
553      * @throws LockedException Raised if this instance is locked because loading
554      *                         is in progress.
555      */
556     public void setAllowDuplicateVerticesInChunk(final boolean allow) throws LockedException {
557         if (isLocked()) {
558             throw new LockedException();
559         }
560         internalSetAllowDuplicateVerticesInChunk(allow);
561     }
562 
563     /**
564      * Returns maximum number of stream positions to be cached.
565      * This loader keeps track of a set of stream positions that have been
566      * parsed on ASCII mode. By keeping a cache of positions loading times can
567      * be largely reduced at the expense of using more memory during loading.
568      * By default, this is set to 1000000 positions.
569      * This only has effect on ASCII PLY files. For binary PLY files this
570      * setting is ignored.
571      *
572      * @return maximum number of stream positions to be cached.
573      */
574     public long getMaxStreamPositions() {
575         return maxStreamPositions;
576     }
577 
578     /**
579      * Sets maximum number of stream positions to be cached.
580      * This loader keeps track of a set of stream positions that have been
581      * parsed on ASCII mode. By keeping a cache of positions loading times can
582      * be largely reduced at the expense of using more memory during loading.
583      * By default, this is set to 1000000 positions.
584      * This only has effect on ASCII PLY files. For binary PLY files this
585      * setting is ignored.
586      *
587      * @param maxStreamPositions Maximum number of stream positions to be cached.
588      * @throws IllegalArgumentException Raised if provided value is lower than
589      *                                  DEFAULT_MAX_STREAM_POSITIONS.
590      * @throws LockedException          Raised if this instance is locked because loading
591      *                                  is in progress.
592      */
593     public void setMaxStreamPositions(final long maxStreamPositions) throws LockedException {
594         if (isLocked()) {
595             throw new LockedException();
596         }
597         internalSetMaxStreamPositions(maxStreamPositions);
598     }
599 
600     /**
601      * Indicates it this loader has enough parameters to start the loading
602      * process.
603      *
604      * @return True if ready, false otherwise.
605      */
606     @Override
607     public boolean isReady() {
608         return hasFile();
609     }
610 
611     /**
612      * Returns mesh format supported by this loader, which is PLY_MESH_FORMAT.
613      *
614      * @return Format supported by this loader, which is PLY_MESH_FORMAT.
615      */
616     @Override
617     public MeshFormat getMeshFormat() {
618         return MeshFormat.MESH_FORMAT_PLY;
619     }
620 
621     /**
622      * Reads the header of provided file and determines whether file is valid or
623      * not.
624      *
625      * @return True if file is a valid PLY file, false otherwise.
626      * @throws LockedException Raised if this instance is locked because loading
627      *                         is in progress.
628      * @throws IOException     if an i/O error occurs.
629      */
630     @Override
631     public boolean isValidFile() throws LockedException, IOException {
632         if (isLocked()) {
633             throw new LockedException();
634         }
635 
636         if (reader == null) {
637             throw new IOException();
638         }
639 
640         setLocked(true);
641         try {
642             readHeader();
643         } catch (final LoaderException | BufferUnderflowException ex) {
644             validStream = false;
645         } finally {
646             setLocked(false);
647         }
648         return validStream;
649     }
650 
651     /**
652      * Starts the loading process.
653      * This method reads the file header, checks its validity and prepares an
654      * iterator so the loading process can be carried in an iterative process.
655      *
656      * @return Iterator to load the file in small chunks of data.
657      * @throws LockedException   Raised if this instance is locked because loading
658      *                           is in progress.
659      * @throws NotReadyException raised if this instance is not yet ready
660      *                           because not enough parameters have been set.
661      * @throws IOException       if an I/O error occurs.
662      * @throws LoaderException   Raised if file is not a valid PLY or is corrupted.
663      */
664     @Override
665     public LoaderIterator load() throws LockedException, NotReadyException, IOException, LoaderException {
666         if (!isReady()) {
667             throw new NotReadyException();
668         }
669 
670         readFromStream();
671         return loaderIterator;
672     }
673 
674     /**
675      * Internal method to set maximum number of vertices to keep in a chunk of
676      * data.
677      *
678      * @param maxVerticesInChunk Indicates maximum number of vertices to keep in
679      *                           a chunk of data.
680      * @throws IllegalArgumentException Raised if maximum number of vertices is
681      *                                  smaller than MIN_MAX_VERTICES_IN_CHUNK.
682      */
683     private void internalSetMaxVerticesInChunk(final int maxVerticesInChunk) {
684         if (maxVerticesInChunk < MIN_MAX_VERTICES_IN_CHUNK) {
685             throw new IllegalArgumentException();
686         }
687 
688         this.maxVerticesInChunk = maxVerticesInChunk;
689     }
690 
691     /**
692      * Internal method to set whether duplicate vertices in a chunk are allowed.
693      * By allowing duplicate vertices, PLY loading can be speed up a little bit
694      * at the expense of getting larger sets of data which will contain
695      * redundant vertices. If your environment is memory constrained, this
696      * should be disabled. By default, it is disabled.
697      *
698      * @param allow Indicates whether duplicates will be allowed or not.
699      */
700     private void internalSetAllowDuplicateVerticesInChunk(final boolean allow) {
701         allowDuplicateVerticesInChunk = allow;
702     }
703 
704     /**
705      * Internal method to set maximum number of stream positions to be cached.
706      * This loader keeps track of a set of stream positions that have been
707      * parsed on ASCII mode. By keeping a cache of positions loading times can
708      * be largely reduced at the expense of using more memory during loading.
709      * By default, this is set to 1000000 positions.
710      * This only has effect on ASCII PLY files. For binary PLY files this
711      * setting is ignored.
712      *
713      * @param maxStreamPositions Maximum number of stream positions to be cached.
714      * @throws IllegalArgumentException Raised if provided value is lower than
715      *                                  DEFAULT_MAX_STREAM_POSITIONS.
716      */
717     private void internalSetMaxStreamPositions(final long maxStreamPositions) {
718         if (maxStreamPositions < MIN_STREAM_POSITIONS) {
719             throw new IllegalArgumentException();
720         }
721 
722         this.maxStreamPositions = maxStreamPositions;
723     }
724 
725     /**
726      * Reads header of provided file and initializes iterator to read data
727      * chunks of this file.
728      *
729      * @throws LockedException Raised if this instance is locked because loading
730      *                         is in progress.
731      * @throws IOException     if an i/O error occurs.
732      * @throws LoaderException Raised if file is not a valid PLY or is corrupted
733      */
734     private void readFromStream() throws LockedException, IOException, LoaderException {
735 
736         if (isLocked()) {
737             throw new LockedException();
738         }
739 
740         setLocked(true);
741         if (listener != null) {
742             listener.onLoadStart(this);
743         }
744 
745         // do not leave this loader locked if file cannot be loaded
746         loaderIterator = loadReleasingLockOnFailure(() -> {
747             if (reader == null) {
748                 throw new IOException();
749             }
750 
751             if (!validityChecked) {
752                 readHeader();
753             }
754             if (!validStream) {
755                 throw new LoaderException();
756             }
757 
758             try {
759                 return new LoaderIteratorPLY(this);
760             } catch (final CorruptValueException e) {
761                 // a value could not be parsed, hence file is corrupted
762                 throw new LoaderException(e);
763             }
764         });
765         loaderIterator.setListener(new LoaderIteratorListenerImpl(this));
766     }
767 
768     /**
769      * Reads the header of provided file.
770      *
771      * @throws IOException     if an I/O error occurs.
772      * @throws LoaderException Raised if file is not a valid PLY or is
773      *                         corrupted.
774      */
775     private void readHeader() throws IOException, LoaderException {
776         if (reader == null) {
777             throw new IOException();
778         }
779 
780         validityChecked = true;
781 
782         // first line must be equal to string "ply"
783         var str = reader.readLine();
784 
785         if (!"ply".equals(str) || reader.isEndOfStream()) {
786             validStream = false;
787             throw new LoaderException();
788         }
789 
790         // second line contains format (i.e: format ascii 1.0)
791         // must start with "format" word
792         do {
793             // loop is to avoid empty strings
794             // (because of duplicate spaces or carriage returns)
795             str = readWordOrEmpty();
796         } while ((str.isEmpty()) && !reader.isEndOfStream());
797 
798         if (!"format".equals(str) || reader.isEndOfStream()) {
799             validStream = false;
800             throw new LoaderException();
801         }
802 
803         // next to format word comes storage mode
804         do {
805             // loop to avoid empty strings
806             str = readWordOrEmpty();
807         } while ((str.isEmpty()) && !reader.isEndOfStream());
808 
809         if (reader.isEndOfStream()) {
810             validStream = false;
811             throw new LoaderException();
812         }
813 
814         final PLYStorageMode storageMode = switch (str) {
815             case "ascii" ->
816                 // ASCII storage mode
817                     PLYStorageMode.PLY_ASCII;
818             case "binary_big_endian" ->
819                 // Binary big endian storage mode
820                     PLYStorageMode.PLY_BIG_ENDIAN;
821             case "binary_little_endian" ->
822                 // Binary little endian storage mode
823                     PLYStorageMode.PLY_LITTLE_ENDIAN;
824             default -> {
825                 // non supported storage mode
826                 validStream = false;
827                 throw new LoaderException();
828             }
829         };
830 
831         // next comes version (always must be 1.0)
832         do {
833             // loop to avoid empty strings
834             str = readWordOrEmpty();
835         } while ((str.isEmpty()) && !reader.isEndOfStream());
836 
837         if (!"1.0".equals(str) || reader.isEndOfStream()) {
838             validStream = false;
839             throw new LoaderException();
840         }
841 
842         // instantiate header member
843         header = new HeaderPLY();
844         // set storage mode
845         header.setStorageMode(storageMode);
846 
847         // read until we find the line end_header
848         var endOfHeader = false;
849         ElementPLY lastElement = null;
850         PropertyPLY property;
851         do {
852             do {
853                 // loop to avoid empty strings
854                 str = readWordOrEmpty();
855             } while ((str.isEmpty()) && !reader.isEndOfStream());
856 
857             if ("comment".equals(str)) {
858                 // if word is "comment", read until end of line
859                 str = reader.readLine();
860                 // add comment to list of comments in header
861                 header.getComments().add(str);
862             } else if ("obj_info".equals(str)) {
863                 // if word is "obj_info", read until end of line
864                 str = reader.readLine();
865                 // add obj_info to list of obj_infos in header
866                 header.getObjInfos().add(str);
867             } else if (str.endsWith("element")) {
868                 // and element has been found. We read its information and
869                 // add it to the list of elements
870 
871                 // next word contains element name
872                 do {
873                     // loop to avoid empty strings
874                     str = readWordOrEmpty();
875                 } while ((str.isEmpty()) && !reader.isEndOfStream());
876 
877                 if (reader.isEndOfStream()) {
878                     validStream = false;
879                     throw new LoaderException();
880                 }
881 
882                 final var elementName = str;
883 
884                 // next word contains number of instances of this element
885                 do {
886                     str = readWordOrEmpty();
887                 } while ((str.isEmpty()) && !reader.isEndOfStream());
888 
889                 if (reader.isEndOfStream()) {
890                     validStream = false;
891                     throw new LoaderException();
892                 }
893 
894                 final long elementInstances;
895                 try {
896                     elementInstances = Long.parseLong(str);
897                 } catch (NumberFormatException e) {
898                     throw new IOException(e);
899                 }
900 
901                 if (elementInstances < 0) {
902                     // number of instances cannot be negative
903                     validStream = false;
904                     throw new LoaderException();
905                 }
906 
907                 // instantiate element
908                 lastElement = new ElementPLY(elementName, elementInstances);
909 
910                 // add element to header
911                 header.getElements().add(lastElement);
912             } else if ("property".equals(str)) {
913                 // a property for last element that has been found. We read its
914                 // information and add it to the element
915 
916                 if (lastElement == null) {
917                     // no previous element was defined
918                     validStream = false;
919                     throw new LoaderException();
920                 }
921 
922                 // read next word
923                 do {
924                     // loop to avoid empty strings
925                     str = readWordOrEmpty();
926                 } while ((str.isEmpty()) && !reader.isEndOfStream());
927 
928                 if (reader.isEndOfStream()) {
929                     validStream = false;
930                     throw new LoaderException();
931                 }
932 
933                 if ("list".equals(str)) {
934                     // property is a list
935                     final DataTypePLY lengthDataType;
936                     final DataTypePLY valueDataType;
937                     try {
938                         // read length data type
939                         do {
940                             // loop to avoid empty strings
941                             str = readWordOrEmpty();
942                         } while ((str.isEmpty()) && !reader.isEndOfStream());
943 
944                         if (reader.isEndOfStream()) {
945                             validStream = false;
946                             throw new LoaderException();
947                         }
948 
949                         lengthDataType = wordToDataType(str);
950 
951                         // read value data type
952                         do {
953                             str = readWordOrEmpty();
954                         } while ((str.isEmpty()) && !reader.isEndOfStream());
955 
956                         if (reader.isEndOfStream()) {
957                             validStream = false;
958                             throw new LoaderException();
959                         }
960 
961                         valueDataType = wordToDataType(str);
962                     } catch (final LoaderException ex) {
963                         // some error was found
964                         validStream = false;
965                         throw ex;
966                     }
967 
968                     // read property name
969                     do {
970                         str = readWordOrEmpty();
971                     } while ((str.isEmpty()) && !reader.isEndOfStream());
972 
973                     if (reader.isEndOfStream()) {
974                         validStream = false;
975                         throw new LoaderException();
976                     }
977 
978                     final var propertyName = str;
979 
980                     property = new PropertyPLY(propertyName, lengthDataType, valueDataType);
981                 } else {
982                     // property is scalar
983                     // word that we have already read should contain value data
984                     // type
985 
986                     final DataTypePLY valueDataType;
987                     try {
988                         valueDataType = wordToDataType(str);
989                     } catch (final LoaderException ex) {
990                         // invalid data type was found
991                         validStream = false;
992                         throw ex;
993                     }
994                     // read property name
995                     do {
996                         str = readWordOrEmpty();
997                     } while ((str.isEmpty()) && !reader.isEndOfStream());
998 
999                     if (reader.isEndOfStream()) {
1000                         validStream = false;
1001                         throw new LoaderException();
1002                     }
1003 
1004                     final var propertyName = str;
1005 
1006                     property = new PropertyPLY(propertyName, valueDataType);
1007                 }
1008                 try {
1009                     // add property to last element
1010                     lastElement.getProperties().add(property);
1011                 } catch (final NotAvailableException ex) {
1012                     validStream = false;
1013                     throw new LoaderException(ex);
1014                 }
1015             } else if ("end_header".equals(str)) {
1016                 // end of header has been found
1017                 endOfHeader = true;
1018             } else {
1019                 // something else that cannot be understood
1020                 validStream = false;
1021                 throw new LoaderException();
1022             }
1023         } while (!endOfHeader);
1024 
1025         validStream = true;
1026     }
1027 
1028     /**
1029      * Reads next word of the file. At the end of the stream an empty word is
1030      * returned instead of null.
1031      *
1032      * @return next word or an empty string if end of stream has been reached.
1033      * @throws IOException if an I/O error occurs.
1034      */
1035     private String readWordOrEmpty() throws IOException {
1036         final var word = reader.readWord();
1037         return word != null ? word : "";
1038     }
1039 
1040     /**
1041      * Converts a word into a data type. If an unsupported word is found then a
1042      * LoaderException is raised.
1043      *
1044      * @param word word to be converted.
1045      * @return DataType obtained from word.
1046      * @throws LoaderException Raised if file is not a valid PLY or is
1047      *                         corrupted (i.e. an unsupported word is found).
1048      */
1049     private DataTypePLY wordToDataType(final String word) throws LoaderException {
1050         final var dataType = DataTypePLY.forValue(word);
1051         if (dataType == null) {
1052             throw new LoaderException();
1053         }
1054         return dataType;
1055     }
1056 
1057     /**
1058      * Raised when a value stored as text in an ASCII PLY file cannot be
1059      * parsed (e.g. because file is truncated or corrupted). It extends
1060      * {@link IOException} because of the signature of
1061      * {@link PLYReadValueFromStreamListener}, and it is converted into a
1062      * {@link LoaderException} while iterating the file.
1063      */
1064     private static class CorruptValueException extends IOException {
1065 
1066         /**
1067          * Constructor.
1068          *
1069          * @param cause cause of this exception.
1070          */
1071         CorruptValueException(final Throwable cause) {
1072             super(cause);
1073         }
1074     }
1075 
1076     /**
1077      * Internal listener to be notified when loading process finishes.
1078      * This listener is used to free resources when loading process finishes.
1079      */
1080     private class LoaderIteratorListenerImpl implements LoaderIteratorListener {
1081 
1082         /**
1083          * Reference to Loader loading PLY file.
1084          */
1085         private final LoaderPLY loader;
1086 
1087         /**
1088          * Constructor.
1089          *
1090          * @param loader reference to Loader.
1091          */
1092         public LoaderIteratorListenerImpl(final LoaderPLY loader) {
1093             this.loader = loader;
1094         }
1095 
1096         /**
1097          * Called when a loader iterator has no more data to be read.
1098          *
1099          * @param iterator Iterator loading a file.
1100          */
1101         @Override
1102         public void onIteratorFinished(final LoaderIterator iterator) {
1103             // because iterator is finished, we should allow subsequent calls to
1104             // load method
1105             try {
1106                 reader.seek(0); // attempt restart stream to current position
1107             } catch (final Exception ignore) {
1108                 // operation is attempted, if it fails it is ignored
1109             }
1110 
1111             // on subsequent calls
1112             validityChecked = false; // reset in case we want to read more data
1113             if (listener != null) {
1114                 listener.onLoadEnd(loader);
1115             }
1116             setLocked(false);
1117         }
1118     }
1119 
1120     /**
1121      * Internal implementation of a loader iterator for PLY files.
1122      */
1123     private class LoaderIteratorPLY implements LoaderIterator {
1124 
1125         /**
1126          * Reference to a LoaderPLY.
1127          */
1128         private final LoaderPLY loader;
1129 
1130         /**
1131          * Number of elements in a list property.
1132          */
1133         private int listElems;
1134 
1135         /**
1136          * Last x vertex coordinate that was read.
1137          */
1138         private float coordX;
1139 
1140         /**
1141          * Last y vertex coordinate that was read.
1142          */
1143         private float coordY;
1144 
1145         /**
1146          * Last z vertex coordinate that was read.
1147          */
1148         private float coordZ;
1149 
1150         /**
1151          * Last red color component that was read.
1152          */
1153         private short red;
1154 
1155         /**
1156          * Last green color component that was read.
1157          */
1158         private short green;
1159 
1160         /**
1161          * Last blue color component that was read.
1162          */
1163         private short blue;
1164 
1165         /**
1166          * Last alpha color component that was read.
1167          */
1168         private short alpha;
1169 
1170         /**
1171          * Last normal x component that was red.
1172          */
1173         private float nX;
1174 
1175         /**
1176          * Last normal y component that was read.
1177          */
1178         private float nY;
1179 
1180         /**
1181          * Last normal z component that was read.
1182          */
1183         private float nZ;
1184 
1185         /**
1186          * Last vertex index that was read.
1187          */
1188         private long index;
1189 
1190         // coordinates for bounding box in a chunk
1191 
1192         /**
1193          * Minimum x coordinate of all vertices that have been read so far in
1194          * current chunk of data.
1195          */
1196         private float minX;
1197 
1198         /**
1199          * Minimum y coordinate of all vertices that have been read so far in
1200          * current chunk of data.
1201          */
1202         private float minY;
1203 
1204         /**
1205          * Minimum z coordinate of all vertices that have been read so far in
1206          * current chunk of data.
1207          */
1208         private float minZ;
1209 
1210         /**
1211          * Maximum x coordinate of all vertices that have been read so far in
1212          * current chunk of data.
1213          */
1214         private float maxX;
1215 
1216         /**
1217          * Maximum y coordinate of all vertices that have been read so far in
1218          * current chunk of data.
1219          */
1220         private float maxY;
1221 
1222         /**
1223          * Maximum z coordinate of all vertices that have been read so far in
1224          * current chunk of data.
1225          */
1226         private float maxZ;
1227 
1228         /**
1229          * Indicates whether file contains vertices.
1230          */
1231         private boolean verticesAvailable;
1232 
1233         /**
1234          * Indicates whether file contains colors.
1235          */
1236         private boolean colorsAvailable;
1237 
1238         /**
1239          * Indicates whether file contains vertex indices.
1240          */
1241         private boolean indicesAvailable;
1242 
1243         /**
1244          * Indicates whether file contains normals.
1245          */
1246         private boolean normalsAvailable;
1247 
1248         /**
1249          * Indicates number of color components of vertices.
1250          */
1251         private int colorComponents;
1252 
1253         /**
1254          * Stores position where header of file finishes.
1255          */
1256         private long endHeaderStreamPosition;
1257 
1258         /**
1259          * Number of vertices contained in the file.
1260          */
1261         private long numberOfVertices;
1262 
1263         /**
1264          * Number of faces (triangles or polygons) contained in the file.
1265          */
1266         private long numberOfFaces;
1267 
1268         /**
1269          * Stores position where first vertex is located.
1270          */
1271         private long firstVertexStreamPosition;
1272 
1273         /**
1274          * Indicates whether first vertex position has already been read and is
1275          * available.
1276          */
1277         private boolean firstVertexStreamPositionAvailable;
1278 
1279         /**
1280          * Indicates size of vertex data.
1281          */
1282         private long vertexDataSize;
1283 
1284         /**
1285          * Stores position where first vertex index containing a triangle or
1286          * polygon is located.
1287          */
1288         private long firstFaceStreamPosition;
1289 
1290         /**
1291          * Indicates whether first vertex index position has already been read
1292          * and is available.
1293          */
1294         private boolean firstFaceStreamPositionAvailable;
1295 
1296         /**
1297          * Stores current position in file stream.
1298          */
1299         private long currentStreamPosition;
1300 
1301         /**
1302          * Number of instances of a given element in the header of the file
1303          * (i.e. number of vertices or faces).
1304          */
1305         private long totalInstances;
1306 
1307         /**
1308          * A header element that contains vertex properties.
1309          */
1310         private ElementPLY vertexElement;
1311 
1312         /**
1313          * A header element that contains face (triangles/polygons) properties.
1314          */
1315         private ElementPLY faceElement;
1316 
1317         /**
1318          * Current triangle/polygon being read from all faces available in the
1319          * file.
1320          */
1321         private long currentFace;
1322 
1323         /**
1324          * Listener to fetch a vertex position in the stream of data based on
1325          * its vertex index.
1326          * There are implementations for binary and text (ascii) fetchers.
1327          */
1328         private VertexFetcherListener fetchVertexListener;
1329 
1330         /**
1331          * Listener of this iterator that notifies the loader when the iterator
1332          * has finished loading the file, so that the loader becomes unlocked
1333          * again.
1334          */
1335         private LoaderIteratorListener listener;
1336 
1337         /**
1338          * Array containing vertex coordinates in current chunk of data.
1339          * Data is stored sequentially as x1, y1, z1, x2, y2, z2, etc.
1340          */
1341         private float[] coordsInChunkArray;
1342 
1343         /**
1344          * Array containing vertex colors in current chunk of data.
1345          * Data is stored sequentially depending on the number of color
1346          * components. For instance, for RGB this would be: r1, g1, b1, r2, g2,
1347          * b2, etc.
1348          */
1349         private short[] colorsInChunkArray;
1350 
1351         /**
1352          * Indices of vertices in current chunk.
1353          * Indices are stored sequentially in sets of 3 forming triangles like
1354          * this: t1a, t1b, t1c, t2a, t2b, t2c, etc.
1355          */
1356         private int[] indicesInChunkArray;
1357 
1358         /**
1359          * Indices of vertices in file. Original indices might differ of indices
1360          * numeration in current chunk because for each chunk indices start
1361          * again at zero. Indices are stored sequentially in sets of 3
1362          * forming triangles like: t1a, t1b, t1c, t2a, t2b, t2c, etc.
1363          */
1364         private long[] originalIndicesInChunkArray;
1365 
1366         /**
1367          * Normals of vertices in current chunk.
1368          * Normals are stored sequentially for each vertex like this: n1x, n1y,
1369          * n1z, n2x, n2y, n2z, etc.
1370          */
1371         private float[] normalsInChunkArray;
1372 
1373         /**
1374          * Number of vertices currently stored in chunk.
1375          * This is used to determine when no more vertices can be stored in
1376          * a chunk and an additional chunk needs to be loaded.
1377          */
1378         private int verticesInChunk;
1379 
1380         /**
1381          * Number of indices currently stored in chunk.
1382          */
1383         private int indicesInChunk;
1384 
1385         /**
1386          * Number of indices used as a default to initialize arrays.
1387          * When the number of indices exceeds this value arrays will be resized.
1388          */
1389         private int indicesInChunkSize;
1390 
1391         /**
1392          * Stores current stream position so that vertices positions can be
1393          * cached.
1394          */
1395         private long vertexStreamPosition;
1396 
1397         /**
1398          * Map containing relations between original indices of the stream (key)
1399          * and their corresponding index in the chunk (value).
1400          */
1401         private final TreeMap<Long, Integer> indicesMap;
1402 
1403         /**
1404          * Map relating original indices in stream (key) and stream positions
1405          * (value).
1406          */
1407         private final TreeMap<Long, Long> verticesStreamPositionsMap;
1408 
1409         /**
1410          * Constructor.
1411          *
1412          * @param loader Reference to the loader controlling this iterator.
1413          * @throws LoaderException Raised if file is corrupted and cannot be
1414          *                         loaded.
1415          * @throws IOException     if an I/O error occurs.
1416          */
1417         public LoaderIteratorPLY(final LoaderPLY loader) throws LoaderException, IOException {
1418             this.loader = loader;
1419             listElems = 1;
1420             nX = nY = nZ = 1.0f;
1421             alpha = 255;
1422             index = 0;
1423             colorComponents = 0;
1424             verticesAvailable = colorsAvailable = indicesAvailable = normalsAvailable = false;
1425             endHeaderStreamPosition = numberOfVertices = numberOfFaces = 0;
1426             firstVertexStreamPosition = 0;
1427             firstVertexStreamPositionAvailable = false;
1428             vertexDataSize = 0;
1429             firstFaceStreamPositionAvailable = false;
1430             currentStreamPosition = 0;
1431             totalInstances = 0;
1432             vertexElement = faceElement = null;
1433             currentFace = 0;
1434             fetchVertexListener = null;
1435             listener = null;
1436             coordsInChunkArray = null;
1437             colorsInChunkArray = null;
1438             indicesInChunkArray = null;
1439             originalIndicesInChunkArray = null;
1440             normalsInChunkArray = null;
1441             verticesInChunk = indicesInChunk = 0;
1442             indicesInChunkSize = 0;
1443             vertexStreamPosition = 0;
1444             indicesMap = new TreeMap<>();
1445             verticesStreamPositionsMap = new TreeMap<>();
1446 
1447             minX = minY = minZ = Float.MAX_VALUE;
1448             maxX = maxY = maxZ = -Float.MAX_VALUE;
1449 
1450             setUp();
1451         }
1452 
1453         /**
1454          * Sets listener to notify when this iterator has finished loading the
1455          * PLY file.
1456          *
1457          * @param listener listener to notify when this iterator has finished
1458          *                 loading the PLY file.
1459          */
1460         public void setListener(final LoaderIteratorListener listener) {
1461             this.listener = listener;
1462         }
1463 
1464         /**
1465          * Indicates if there are still more chunks of data to be read on this
1466          * PLY file.
1467          *
1468          * @return True if there are more chunks of data, false otherwise.
1469          */
1470         @Override
1471         public boolean hasNext() {
1472             return (currentFace < numberOfFaces);
1473         }
1474 
1475         /**
1476          * Reads next chunk of data from PLY file.
1477          *
1478          * @return A chunk of data containing vertex coordinates, colors, vertex
1479          * normals, textures, etc.
1480          * @throws NotAvailableException Raised if no more chunks are available.
1481          * @throws LoaderException       Raised if file is corrupted and cannot be
1482          *                               loaded.
1483          * @throws IOException           Raised if an I/O error occurs.
1484          */
1485         @Override
1486         public DataChunk next() throws NotAvailableException, LoaderException, IOException {
1487 
1488             if (reader == null) {
1489                 throw new IOException();
1490             }
1491 
1492             if (!hasNext()) {
1493                 throw new NotAvailableException();
1494             }
1495 
1496             // do not leave loader locked if file cannot be read
1497             return readReleasingLockOnFailure(() -> {
1498                 try {
1499                     return readNextChunk();
1500                 } catch (final CorruptValueException e) {
1501                     // a value could not be parsed, hence file is corrupted
1502                     throw new LoaderException(e);
1503                 }
1504             });
1505         }
1506 
1507         /**
1508          * Reads next chunk of data.
1509          *
1510          * @return next chunk of data.
1511          * @throws NotAvailableException if no more data is available.
1512          * @throws LoaderException       if file data is corrupt or cannot be
1513          *                               understood.
1514          * @throws IOException           if an I/O error occurs.
1515          */
1516         @SuppressWarnings("all")
1517         private DataChunk readNextChunk()
1518                 throws NotAvailableException, LoaderException, IOException {
1519             initChunkArrays();
1520 
1521             // reset chunk bounding box values
1522             minX = minY = minZ = Float.MAX_VALUE;
1523             maxX = maxY = maxZ = -Float.MAX_VALUE;
1524 
1525             final var buffer = ByteBuffer.allocate(BUFFER_SIZE);
1526 
1527             final var nElems = faceElement.getNumberOfInstances();
1528             final var progressStep = Math.max((long) (LoaderPLY.PROGRESS_DELTA * nElems), 1);
1529 
1530             var end = false;
1531 
1532             // initialize list indices to a list of one element to be reused
1533             var previousListElems = 1;
1534             var listIndices = new long[previousListElems];
1535 
1536             while ((currentFace < nElems) && !end) {
1537 
1538                 final var faceStreamPos = reader.getPosition();
1539                 // Iterate on properties
1540                 for (final var property : faceElement.getProperties()) {
1541                     if (!property.isValidProperty()) {
1542                         throw new LoaderException();
1543                     }
1544 
1545                     // number of elements in list (initially assume that is
1546                     // scalar, hence 1)
1547                     listElems = 1;
1548 
1549                     // set listeners to read property length value
1550                     PLYReadValueFromStreamListener readValueFromStreamListener =
1551                             property.getReadLengthValueFromStreamListener();
1552                     PLYReadValueFromBufferListener readValueFromBufferListener =
1553                             property.getReadLengthValueFromBufferListener();
1554 
1555                     if (property.getPropertyType() == PropertyTypePLY.PROPERTY_PLY_LIST) {
1556                         // read number of list elements
1557                         readValueFromStreamListener.readFromStream(buffer);
1558 
1559                         if (reader.isEndOfStream() && (currentFace < (nElems - 1))) {
1560                             throw new LoaderException();
1561                         }
1562 
1563                         // set listElems
1564                         readValueFromBufferListener.readValueFromBuffer(buffer);
1565                     }
1566 
1567                     var needsTriangulation = false;
1568                     if (listElems > 3) {
1569                         needsTriangulation = true;
1570                     } else if (listElems < 3) {
1571                         // list does not form a triangle or polygon
1572                         throw new LoaderException();
1573                     }
1574 
1575                     if (listElems > loader.maxVerticesInChunk) {
1576                         // this list will never fit in a chunk with current
1577                         // maxVerticesInChunk setting
1578                         throw new LoaderException();
1579                     }
1580 
1581                     if ((verticesInChunk + listElems) > loader.maxVerticesInChunk) {
1582                         // no more vertices can be added to chunk so we reset stream
1583                         // to start on current face
1584                         reader.seek(faceStreamPos);
1585                         end = true;
1586                         break;
1587                     }
1588 
1589                     // set listeners to read property value
1590                     readValueFromStreamListener = property.getReadValueFromStreamListener();
1591                     readValueFromBufferListener = property.getReadValueFromBufferListener();
1592 
1593                     if (previousListElems != listElems) {
1594                         // listIndices can no longer be reused
1595                         listIndices = new long[listElems];
1596                     }
1597 
1598                     // read property list data
1599                     for (var u = 0; u < listElems; u++) {
1600                         // reads face index from stream and saves it into buffer
1601                         readValueFromStreamListener.readFromStream(buffer);
1602 
1603                         if (reader.isEndOfStream() && (currentFace < (nElems - 1))) {
1604                             throw new LoaderException();
1605                         }
1606 
1607                         // copies buffer content into index member doing proper
1608                         // type conversion
1609                         readValueFromBufferListener.readValueFromBuffer(buffer);
1610 
1611                         listIndices[u] = index;
1612                     }
1613 
1614                     // keep current face stream position
1615                     currentStreamPosition = reader.getPosition();
1616 
1617                     if (needsTriangulation) {
1618                         // search vertices data corresponding to read indices
1619                         final var polygonVertices = new ArrayList<Point3D>(listElems);
1620                         for (var u = 0; u < listElems; u++) {
1621                             index = listIndices[u];
1622                             // vertex needs to be added into chunk, so we need to
1623                             // read vertex data
1624 
1625                             // fetch vertex data position
1626                             fetchVertexListener.fetch(index);
1627 
1628                             // read all vertex data
1629                             for (final var vertexProperty : vertexElement.getProperties()) {
1630 
1631                                 // set delegates to read property value from stream
1632                                 readValueFromStreamListener = vertexProperty.getReadValueFromStreamListener();
1633 
1634                                 // read property from stream to buffer
1635                                 readValueFromStreamListener.readFromStream(buffer);
1636 
1637                                 if (vertexProperty.isReadValueFromBufferListenerAvailable()) {
1638                                     // only read from buffer if property is recognized by this class
1639                                     readValueFromBufferListener = vertexProperty.getReadValueFromBufferListener();
1640 
1641                                     // move value from buffer to apropriate member
1642                                     readValueFromBufferListener.readValueFromBuffer(buffer);
1643                                 }
1644                             }
1645 
1646                             final var point = new InhomogeneousPoint3D(coordX, coordY, coordZ);
1647                             polygonVertices.add(point);
1648                         }
1649 
1650                         try {
1651                             listIndices = buildTriangulatedIndices(polygonVertices, listIndices);
1652                             listElems = listIndices.length;
1653                         } catch (final TriangulatorException e) {
1654                             // reset face stream position
1655                             reader.seek(currentStreamPosition);
1656                             continue;
1657                         }
1658                     }
1659 
1660                     // search for vertices indices contained in list
1661                     for (var u = 0; u < listElems; u++) {
1662                         index = listIndices[u];
1663                         // index contains original face index in PLY file
1664                         int chunkIndex;
1665                         if (!loader.allowDuplicateVerticesInChunk && (chunkIndex = searchIndexInChunk(index)) >= 0) {
1666                             // vertex is already stored in chunk with chunkIndex
1667                             addExistingVertexToChunk(chunkIndex);
1668                         } else {
1669                             // vertex needs to be added into chunk, so we need to
1670                             // read vertex data
1671 
1672                             // fetch vertex data position
1673                             fetchVertexListener.fetch(index);
1674 
1675                             // read all vertex data
1676                             for (final var vertexProperty : vertexElement.getProperties()) {
1677 
1678                                 // set delegates to read property value from stream
1679                                 readValueFromStreamListener = vertexProperty.getReadValueFromStreamListener();
1680 
1681                                 // read property from stream to buffer
1682                                 readValueFromStreamListener.readFromStream(buffer);
1683 
1684                                 if (vertexProperty.isReadValueFromBufferListenerAvailable()) {
1685                                     // only read from buffer if property is recognized by this class
1686                                     readValueFromBufferListener = vertexProperty.getReadValueFromBufferListener();
1687 
1688                                     // move value from buffer to apropriate member
1689                                     readValueFromBufferListener.readValueFromBuffer(buffer);
1690                                 }
1691                             }
1692 
1693                             // store all vertex data into chunk arrays
1694                             addNewVertexDataToChunk();
1695                         }
1696                     }
1697 
1698                     // reset face stream position
1699                     reader.seek(currentStreamPosition);
1700 
1701                     // to reduce memory consumption and delete listIndices
1702                     if (previousListElems != listElems) {
1703                         // list indices haven't been reused
1704 
1705                         // update previousListElems
1706                         previousListElems = listElems;
1707                     }
1708                 }
1709 
1710                 if (!end) {
1711                     currentFace++;
1712                 }
1713 
1714                 // compute progress
1715                 if (loader.listener != null) {
1716                     if ((currentFace % progressStep) == 0) {
1717                         loader.listener.onLoadProgressChange(loader, (float) (currentFace) / (float) (nElems));
1718                     }
1719                 }
1720             }
1721 
1722             // trim arrays to store only needed data
1723             trimArrays();
1724 
1725             // Instantiate DataChunk with chunk arrays
1726             final var dataChunk = new DataChunk();
1727             if (verticesAvailable) {
1728                 dataChunk.setVerticesCoordinatesData(coordsInChunkArray);
1729                 dataChunk.setMinX(minX);
1730                 dataChunk.setMinY(minY);
1731                 dataChunk.setMinZ(minZ);
1732                 dataChunk.setMaxX(maxX);
1733                 dataChunk.setMaxY(maxY);
1734                 dataChunk.setMaxZ(maxZ);
1735             } else {
1736                 // so it can be garbage collected
1737                 coordsInChunkArray = null;
1738             }
1739 
1740             if (colorsAvailable) {
1741                 dataChunk.setColorData(colorsInChunkArray);
1742                 dataChunk.setColorComponents(colorComponents);
1743             } else {
1744                 // so it can be garbage collected
1745                 colorsInChunkArray = null;
1746             }
1747 
1748             if (indicesAvailable) {
1749                 dataChunk.setIndicesData(indicesInChunkArray);
1750             } else {
1751                 // so it can be garbage collected
1752                 indicesInChunkArray = null;
1753             }
1754 
1755             if (normalsAvailable) {
1756                 dataChunk.setNormalsData(normalsInChunkArray);
1757             } else {
1758                 // so it can be garbage collected
1759                 normalsInChunkArray = null;
1760             }
1761 
1762             if (!hasNext()) {
1763                 // notify iterator finished
1764                 if (listener != null) {
1765                     listener.onIteratorFinished(this);
1766                 }
1767             }
1768 
1769             // if no more chunks are available, then close input reader
1770             if (!hasNext()) {
1771                 reader.close();
1772             }
1773 
1774             return dataChunk;
1775         }
1776 
1777         /**
1778          * Triangulates provided polygon having vertices corresponding to
1779          * provided indices and returns an array of indices corresponding to the
1780          * triangles forming the polygon.
1781          *
1782          * @param polygonVertices vertices forming a polygon to be triangulated.
1783          * @param plyIndices      indices corresponding to provided polygon.
1784          * @return array of indices corresponding to the triangles forming the
1785          * polygon.
1786          * @throws TriangulatorException if triangulation fails because polygon
1787          *                               is degenerate or vertices contains invalid values such as NaN or
1788          *                               infinity.
1789          */
1790         private long[] buildTriangulatedIndices(final List<Point3D> polygonVertices, final long[] plyIndices)
1791                 throws TriangulatorException {
1792 
1793             final var indices = new ArrayList<int[]>();
1794             final var triangulator = Triangulator3D.create();
1795             final var triangles = triangulator.triangulate(polygonVertices, indices);
1796 
1797             final var result = new long[triangles.size() * 3];
1798             var pos = 0;
1799             long plyIndex;
1800             for (final var triangleIndices : indices) {
1801                 for (final var triangleIndex : triangleIndices) {
1802                     plyIndex = plyIndices[triangleIndex];
1803                     result[pos] = plyIndex;
1804                     pos++;
1805                 }
1806             }
1807 
1808             return result;
1809         }
1810 
1811 
1812         /**
1813          * Initializes arrays where chunk data will be stored.
1814          */
1815         private void initChunkArrays() {
1816             coordsInChunkArray = new float[loader.maxVerticesInChunk * 3];
1817             colorsInChunkArray = new short[loader.maxVerticesInChunk * colorComponents];
1818             indicesInChunkArray = new int[loader.maxVerticesInChunk];
1819             originalIndicesInChunkArray = new long[loader.maxVerticesInChunk];
1820             normalsInChunkArray = new float[loader.maxVerticesInChunk * 3];
1821             verticesInChunk = 0;
1822             indicesInChunk = 0;
1823             indicesInChunkSize = loader.maxVerticesInChunk;
1824             indicesMap.clear();
1825         }
1826 
1827         /**
1828          * Searches corresponding index in chunk for provided stream vertex
1829          * index.
1830          *
1831          * @param originalIndex Index in original stream of data.
1832          * @return Vertex index in current chunk of data.
1833          */
1834         private int searchIndexInChunk(final long originalIndex) {
1835             final var chunkIndex = indicesMap.get(originalIndex);
1836 
1837             if (chunkIndex == null) {
1838                 return -1;
1839             }
1840 
1841             return indicesInChunkArray[chunkIndex];
1842         }
1843 
1844         /**
1845          * Caches provided vertex index to relate it to given stream position
1846          * where vertex data can be found.
1847          * This method only has effect for ASCII PLY files.
1848          *
1849          * @param originalIndex  Vertex index in original stream of data.
1850          * @param streamPosition Stream position where vertex is found.
1851          */
1852         private void addVertexPositionToMap(final long originalIndex, final long streamPosition) {
1853             if (loader.header.getStorageMode() == PLYStorageMode.PLY_ASCII) {
1854                 if (verticesStreamPositionsMap.size() > loader.maxStreamPositions) {
1855                     // Map is full. Remove 1st item before adding a new one
1856                     final var origIndex = verticesStreamPositionsMap.firstKey();
1857                     verticesStreamPositionsMap.remove(origIndex);
1858                 }
1859                 // add new item
1860                 verticesStreamPositionsMap.put(originalIndex, streamPosition);
1861             }
1862         }
1863 
1864         /**
1865          * Adds data of last vertex that has been read to the arrays of current
1866          * chunk of data.
1867          */
1868         private void addNewVertexDataToChunk() {
1869             var pos = 3 * verticesInChunk;
1870             var colorPos = colorComponents * verticesInChunk;
1871             coordsInChunkArray[pos] = coordX;
1872             normalsInChunkArray[pos] = nX;
1873             if (colorComponents >= 1) {
1874                 colorsInChunkArray[colorPos] = red;
1875             }
1876 
1877             pos++;
1878             colorPos++;
1879 
1880             coordsInChunkArray[pos] = coordY;
1881             normalsInChunkArray[pos] = nY;
1882             if (colorComponents >= 2) {
1883                 colorsInChunkArray[colorPos] = green;
1884             }
1885 
1886             pos++;
1887             colorPos++;
1888 
1889             coordsInChunkArray[pos] = coordZ;
1890             normalsInChunkArray[pos] = nZ;
1891             if (colorComponents >= 3) {
1892                 colorsInChunkArray[colorPos] = blue;
1893             }
1894 
1895             if (colorComponents >= 4) {
1896                 colorPos++;
1897                 colorsInChunkArray[colorPos] = alpha;
1898             }
1899 
1900             // update bounding box values
1901             if (coordX < minX) {
1902                 minX = coordX;
1903             }
1904             if (coordY < minY) {
1905                 minY = coordY;
1906             }
1907             if (coordZ < minZ) {
1908                 minZ = coordZ;
1909             }
1910 
1911             if (coordX > maxX) {
1912                 maxX = coordX;
1913             }
1914             if (coordY > maxY) {
1915                 maxY = coordY;
1916             }
1917             if (coordZ > maxZ) {
1918                 maxZ = coordZ;
1919             }
1920 
1921             // if arrays of indices become full, we need to resize them
1922             if (indicesInChunk >= indicesInChunkSize) {
1923                 increaseIndicesArraySize();
1924             }
1925             indicesInChunkArray[indicesInChunk] = verticesInChunk;
1926             originalIndicesInChunkArray[indicesInChunk] = index;
1927             // store original index in map, so we can search chunk index by
1928             // original index
1929             indicesMap.put(index, indicesInChunk);
1930 
1931             // store vertex stream position in ascii mode
1932             addVertexPositionToMap(index, vertexStreamPosition);
1933 
1934             verticesInChunk++;
1935             indicesInChunk++;
1936         }
1937 
1938         /**
1939          * Adds provided vertex index into chunk of data.
1940          * This method is only called when duplicate vertices are allowed in
1941          * chunks of data.
1942          *
1943          * @param existingIndex Index to be added into chunk.
1944          */
1945         private void addExistingVertexToChunk(final int existingIndex) {
1946             // if arrays of indices become full, we need to resize them
1947             if (indicesInChunk >= indicesInChunkSize) {
1948                 increaseIndicesArraySize();
1949             }
1950             indicesInChunkArray[indicesInChunk] = existingIndex;
1951             originalIndicesInChunkArray[indicesInChunk] = index;
1952 
1953             indicesInChunk++;
1954         }
1955 
1956         /**
1957          * This method increases the size of arrays containing data of current
1958          * chunk. This method is called when arrays get full and need to be
1959          * enlarged.
1960          */
1961         private void increaseIndicesArraySize() {
1962             final var newIndicesInChunkSize = indicesInChunkSize + loader.maxVerticesInChunk;
1963             final var newIndicesInChunkArray = new int[newIndicesInChunkSize];
1964             final var newOriginalIndicesInChunkArray = new long[newIndicesInChunkSize];
1965 
1966             // copy contents of old arrays
1967             System.arraycopy(indicesInChunkArray, 0, newIndicesInChunkArray, 0, indicesInChunkSize);
1968             System.arraycopy(originalIndicesInChunkArray, 0, newOriginalIndicesInChunkArray, 0,
1969                     indicesInChunkSize);
1970 
1971             // set new arrays and new size
1972             indicesInChunkArray = newIndicesInChunkArray;
1973             originalIndicesInChunkArray = newOriginalIndicesInChunkArray;
1974             indicesInChunkSize = newIndicesInChunkSize;
1975         }
1976 
1977         /**
1978          * This method removes unnecessary data of arrays.
1979          * This method is called when finishing the processing of current chunk
1980          * of data.
1981          */
1982         private void trimArrays() {
1983             if (verticesInChunk > 0) {
1984                 final var elems = verticesInChunk * 3;
1985                 final var colorElems = verticesInChunk * colorComponents;
1986 
1987                 final var newCoordsInChunkArray = new float[elems];
1988                 final var newColorsInChunkArray = new short[colorElems];
1989                 final var newNormalsInChunkArray = new float[elems];
1990 
1991                 // copy contents of old arrays
1992                 System.arraycopy(coordsInChunkArray, 0, newCoordsInChunkArray, 0, elems);
1993                 System.arraycopy(colorsInChunkArray, 0, newColorsInChunkArray, 0, colorElems);
1994                 System.arraycopy(normalsInChunkArray, 0, newNormalsInChunkArray, 0, elems);
1995 
1996                 // set new arrays
1997                 coordsInChunkArray = newCoordsInChunkArray;
1998                 colorsInChunkArray = newColorsInChunkArray;
1999                 normalsInChunkArray = newNormalsInChunkArray;
2000             } else {
2001                 // allow garbage collection
2002                 coordsInChunkArray = null;
2003                 colorsInChunkArray = null;
2004                 normalsInChunkArray = null;
2005             }
2006 
2007             if (indicesInChunk > 0) {
2008                 final var newIndicesInChunkArray = new int[indicesInChunk];
2009                 System.arraycopy(indicesInChunkArray, 0, newIndicesInChunkArray, 0, indicesInChunk);
2010 
2011                 // set new array
2012                 indicesInChunkArray = newIndicesInChunkArray;
2013             } else {
2014                 // allow garbage collection
2015                 indicesInChunkArray = null;
2016                 originalIndicesInChunkArray = null;
2017             }
2018         }
2019 
2020         /**
2021          * Reads header data to set up listeners capable of reading stream data
2022          * according to data types contained in header.
2023          *
2024          * @throws LoaderException Raised if file is corrupted (header is
2025          *                         invalid).
2026          * @throws IOException     if an I/O error occurs.
2027          */
2028         private void setUp() throws LoaderException, IOException {
2029             endHeaderStreamPosition = reader.getPosition();
2030             var streamPositionOffset = endHeaderStreamPosition;
2031 
2032             // read header to set up listeners
2033             try {
2034                 totalInstances = 0;
2035                 colorComponents = 0;
2036                 for (final var element : loader.header.getElements()) {
2037                     if (!element.isValidElement()) {
2038                         throw new LoaderException();
2039                     }
2040                     totalInstances += element.getNumberOfInstances();
2041 
2042                     if ("vertex".equals(element.getName())) {
2043                         vertexElement = element;
2044 
2045                         // obtain position of first vertex
2046 
2047                         // obtain number of vertices
2048                         numberOfVertices = element.getNumberOfInstances();
2049 
2050                         vertexDataSize = 0;
2051                         for (final var property : element.getProperties()) {
2052 
2053                             // set listener to read data from stream
2054                             setReadValueFromStreamListener(property, loader.header.getStorageMode());
2055 
2056                             // set listener to read data stored in buffer
2057                             switch (property.getName()) {
2058                                 case "x":
2059                                     verticesAvailable = true;
2060                                     switch (property.getValueType()) {
2061                                         case PLY_INT8:
2062                                             property.setReadValueFromBufferListener(
2063                                                     new Xint8ReadValueFromBufferListener());
2064                                             break;
2065                                         case PLY_UINT8:
2066                                             property.setReadValueFromBufferListener(
2067                                                     new Xuint8ReadValueFromBufferListener());
2068                                             break;
2069                                         case PLY_INT16:
2070                                             property.setReadValueFromBufferListener(
2071                                                     new Xint16ReadValueFromBufferListener());
2072                                             break;
2073                                         case PLY_UINT16:
2074                                             property.setReadValueFromBufferListener(
2075                                                     new Xuint16ReadValueFromBufferListener());
2076                                             break;
2077                                         case PLY_INT32:
2078                                             property.setReadValueFromBufferListener(
2079                                                     new Xint32ReadValueFromBufferListener());
2080                                             break;
2081                                         case PLY_UINT32:
2082                                             property.setReadValueFromBufferListener(
2083                                                     new Xuint32ReadValueFromBufferListener());
2084                                             break;
2085                                         case PLY_FLOAT32:
2086                                             property.setReadValueFromBufferListener(
2087                                                     new Xfloat32ReadValueFromBufferListener());
2088                                             break;
2089                                         case PLY_FLOAT64:
2090                                             property.setReadValueFromBufferListener(
2091                                                     new Xfloat64ReadValueFromBufferListener());
2092                                             break;
2093                                         case PLY_CHAR:
2094                                             property.setReadValueFromBufferListener(
2095                                                     new XcharReadValueFromBufferListener());
2096                                             break;
2097                                         case PLY_UCHAR:
2098                                             property.setReadValueFromBufferListener(
2099                                                     new XucharReadValueFromBufferListener());
2100                                             break;
2101                                         case PLY_SHORT:
2102                                             property.setReadValueFromBufferListener(
2103                                                     new XshortReadValueFromBufferListener());
2104                                             break;
2105                                         case PLY_USHORT:
2106                                             property.setReadValueFromBufferListener(
2107                                                     new XushortReadValueFromBufferListener());
2108                                             break;
2109                                         case PLY_INT:
2110                                             property.setReadValueFromBufferListener(
2111                                                     new XintReadValueFromBufferListener());
2112                                             break;
2113                                         case PLY_UINT:
2114                                             property.setReadValueFromBufferListener(
2115                                                     new XuintReadValueFromBufferListener());
2116                                             break;
2117                                         case PLY_FLOAT:
2118                                             property.setReadValueFromBufferListener(
2119                                                     new XfloatReadValueFromBufferListener());
2120                                             break;
2121                                         case PLY_DOUBLE:
2122                                             property.setReadValueFromBufferListener(
2123                                                     new XdoubleReadValueFromBufferListener());
2124                                             break;
2125                                         default:
2126                                             throw new LoaderException();
2127                                     }
2128                                     break;
2129                                 case "y":
2130                                     verticesAvailable = true;
2131                                     switch (property.getValueType()) {
2132                                         case PLY_INT8:
2133                                             property.setReadValueFromBufferListener(
2134                                                     new Yint8ReadValueFromBufferListener());
2135                                             break;
2136                                         case PLY_UINT8:
2137                                             property.setReadValueFromBufferListener(
2138                                                     new Yuint8ReadValueFromBufferListener());
2139                                             break;
2140                                         case PLY_INT16:
2141                                             property.setReadValueFromBufferListener(
2142                                                     new Yint16ReadValueFromBufferListener());
2143                                             break;
2144                                         case PLY_UINT16:
2145                                             property.setReadValueFromBufferListener(
2146                                                     new Yuint16ReadValueFromBufferListener());
2147                                             break;
2148                                         case PLY_INT32:
2149                                             property.setReadValueFromBufferListener(
2150                                                     new Yint32ReadValueFromBufferListener());
2151                                             break;
2152                                         case PLY_UINT32:
2153                                             property.setReadValueFromBufferListener(
2154                                                     new Yuint32ReadValueFromBufferListener());
2155                                             break;
2156                                         case PLY_FLOAT32:
2157                                             property.setReadValueFromBufferListener(
2158                                                     new Yfloat32ReadValueFromBufferListener());
2159                                             break;
2160                                         case PLY_FLOAT64:
2161                                             property.setReadValueFromBufferListener(
2162                                                     new Yfloat64ReadValueFromBufferListener());
2163                                             break;
2164                                         case PLY_CHAR:
2165                                             property.setReadValueFromBufferListener(
2166                                                     new YcharReadValueFromBufferListener());
2167                                             break;
2168                                         case PLY_UCHAR:
2169                                             property.setReadValueFromBufferListener(
2170                                                     new YucharReadValueFromBufferListener());
2171                                             break;
2172                                         case PLY_SHORT:
2173                                             property.setReadValueFromBufferListener(
2174                                                     new YshortReadValueFromBufferListener());
2175                                             break;
2176                                         case PLY_USHORT:
2177                                             property.setReadValueFromBufferListener(
2178                                                     new YushortReadValueFromBufferListener());
2179                                             break;
2180                                         case PLY_INT:
2181                                             property.setReadValueFromBufferListener(
2182                                                     new YintReadValueFromBufferListener());
2183                                             break;
2184                                         case PLY_UINT:
2185                                             property.setReadValueFromBufferListener(
2186                                                     new YuintReadValueFromBufferListener());
2187                                             break;
2188                                         case PLY_FLOAT:
2189                                             property.setReadValueFromBufferListener(
2190                                                     new YfloatReadValueFromBufferListener());
2191                                             break;
2192                                         case PLY_DOUBLE:
2193                                             property.setReadValueFromBufferListener(
2194                                                     new YdoubleReadValueFromBufferListener());
2195                                             break;
2196                                         default:
2197                                             throw new LoaderException();
2198                                     }
2199                                     break;
2200                                 case "z":
2201                                     verticesAvailable = true;
2202                                     switch (property.getValueType()) {
2203                                         case PLY_INT8:
2204                                             property.setReadValueFromBufferListener(
2205                                                     new Zint8ReadValueFromBufferListener());
2206                                             break;
2207                                         case PLY_UINT8:
2208                                             property.setReadValueFromBufferListener(
2209                                                     new Zuint8ReadValueFromBufferListener());
2210                                             break;
2211                                         case PLY_INT16:
2212                                             property.setReadValueFromBufferListener(
2213                                                     new Zint16ReadValueFromBufferListener());
2214                                             break;
2215                                         case PLY_UINT16:
2216                                             property.setReadValueFromBufferListener(
2217                                                     new Zuint16ReadValueFromBufferListener());
2218                                             break;
2219                                         case PLY_INT32:
2220                                             property.setReadValueFromBufferListener(
2221                                                     new Zint32ReadValueFromBufferListener());
2222                                             break;
2223                                         case PLY_UINT32:
2224                                             property.setReadValueFromBufferListener(
2225                                                     new Zuint32ReadValueFromBufferListener());
2226                                             break;
2227                                         case PLY_FLOAT32:
2228                                             property.setReadValueFromBufferListener(
2229                                                     new Zfloat32ReadValueFromBufferListener());
2230                                             break;
2231                                         case PLY_FLOAT64:
2232                                             property.setReadValueFromBufferListener(
2233                                                     new Zfloat64ReadValueFromBufferListener());
2234                                             break;
2235                                         case PLY_CHAR:
2236                                             property.setReadValueFromBufferListener(
2237                                                     new ZcharReadValueFromBufferListener());
2238                                             break;
2239                                         case PLY_UCHAR:
2240                                             property.setReadValueFromBufferListener(
2241                                                     new ZucharReadValueFromBufferListener());
2242                                             break;
2243                                         case PLY_SHORT:
2244                                             property.setReadValueFromBufferListener(
2245                                                     new ZshortReadValueFromBufferListener());
2246                                             break;
2247                                         case PLY_USHORT:
2248                                             property.setReadValueFromBufferListener(
2249                                                     new ZushortReadValueFromBufferListener());
2250                                             break;
2251                                         case PLY_INT:
2252                                             property.setReadValueFromBufferListener(
2253                                                     new ZintReadValueFromBufferListener());
2254                                             break;
2255                                         case PLY_UINT:
2256                                             property.setReadValueFromBufferListener(
2257                                                     new ZuintReadValueFromBufferListener());
2258                                             break;
2259                                         case PLY_FLOAT:
2260                                             property.setReadValueFromBufferListener(
2261                                                     new ZfloatReadValueFromBufferListener());
2262                                             break;
2263                                         case PLY_DOUBLE:
2264                                             property.setReadValueFromBufferListener(
2265                                                     new ZdoubleReadValueFromBufferListener());
2266                                             break;
2267                                         default:
2268                                             throw new LoaderException();
2269                                     }
2270                                     break;
2271                                 case "nx":
2272                                     normalsAvailable = true;
2273                                     switch (property.getValueType()) {
2274                                         case PLY_INT8:
2275                                             property.setReadValueFromBufferListener(
2276                                                     new NXint8ReadValueFromBufferListener());
2277                                             break;
2278                                         case PLY_UINT8:
2279                                             property.setReadValueFromBufferListener(
2280                                                     new NXuint8ReadValueFromBufferListener());
2281                                             break;
2282                                         case PLY_INT16:
2283                                             property.setReadValueFromBufferListener(
2284                                                     new NXint16ReadValueFromBufferListener());
2285                                             break;
2286                                         case PLY_UINT16:
2287                                             property.setReadValueFromBufferListener(
2288                                                     new NXuint16ReadValueFromBufferListener());
2289                                             break;
2290                                         case PLY_INT32:
2291                                             property.setReadValueFromBufferListener(
2292                                                     new NXint32ReadValueFromBufferListener());
2293                                             break;
2294                                         case PLY_UINT32:
2295                                             property.setReadValueFromBufferListener(
2296                                                     new NXuint32ReadValueFromBufferListener());
2297                                             break;
2298                                         case PLY_FLOAT32:
2299                                             property.setReadValueFromBufferListener(
2300                                                     new NXfloat32ReadValueFromBufferListener());
2301                                             break;
2302                                         case PLY_FLOAT64:
2303                                             property.setReadValueFromBufferListener(
2304                                                     new NXfloat64ReadValueFromBufferListener());
2305                                             break;
2306                                         case PLY_CHAR:
2307                                             property.setReadValueFromBufferListener(
2308                                                     new NXcharReadValueFromBufferListener());
2309                                             break;
2310                                         case PLY_UCHAR:
2311                                             property.setReadValueFromBufferListener(
2312                                                     new NXucharReadValueFromBufferListener());
2313                                             break;
2314                                         case PLY_SHORT:
2315                                             property.setReadValueFromBufferListener(
2316                                                     new NXshortReadValueFromBufferListener());
2317                                             break;
2318                                         case PLY_USHORT:
2319                                             property.setReadValueFromBufferListener(
2320                                                     new NXushortReadValueFromBufferListener());
2321                                             break;
2322                                         case PLY_INT:
2323                                             property.setReadValueFromBufferListener(
2324                                                     new NXintReadValueFromBufferListener());
2325                                             break;
2326                                         case PLY_UINT:
2327                                             property.setReadValueFromBufferListener(
2328                                                     new NXuintReadValueFromBufferListener());
2329                                             break;
2330                                         case PLY_FLOAT:
2331                                             property.setReadValueFromBufferListener(
2332                                                     new NXfloatReadValueFromBufferListener());
2333                                             break;
2334                                         case PLY_DOUBLE:
2335                                             property.setReadValueFromBufferListener(
2336                                                     new NXdoubleReadValueFromBufferListener());
2337                                             break;
2338                                         default:
2339                                             throw new LoaderException();
2340                                     }
2341                                     break;
2342                                 case "ny":
2343                                     normalsAvailable = true;
2344                                     switch (property.getValueType()) {
2345                                         case PLY_INT8:
2346                                             property.setReadValueFromBufferListener(
2347                                                     new NYint8ReadValueFromBufferListener());
2348                                             break;
2349                                         case PLY_UINT8:
2350                                             property.setReadValueFromBufferListener(
2351                                                     new NYuint8ReadValueFromBufferListener());
2352                                             break;
2353                                         case PLY_INT16:
2354                                             property.setReadValueFromBufferListener(
2355                                                     new NYint16ReadValueFromBufferListener());
2356                                             break;
2357                                         case PLY_UINT16:
2358                                             property.setReadValueFromBufferListener(
2359                                                     new NYuint16ReadValueFromBufferListener());
2360                                             break;
2361                                         case PLY_INT32:
2362                                             property.setReadValueFromBufferListener(
2363                                                     new NYint32ReadValueFromBufferListener());
2364                                             break;
2365                                         case PLY_UINT32:
2366                                             property.setReadValueFromBufferListener(
2367                                                     new NYuint32ReadValueFromBufferListener());
2368                                             break;
2369                                         case PLY_FLOAT32:
2370                                             property.setReadValueFromBufferListener(
2371                                                     new NYfloat32ReadValueFromBufferListener());
2372                                             break;
2373                                         case PLY_FLOAT64:
2374                                             property.setReadValueFromBufferListener(
2375                                                     new NYfloat64ReadValueFromBufferListener());
2376                                             break;
2377                                         case PLY_CHAR:
2378                                             property.setReadValueFromBufferListener(
2379                                                     new NYcharReadValueFromBufferListener());
2380                                             break;
2381                                         case PLY_UCHAR:
2382                                             property.setReadValueFromBufferListener(
2383                                                     new NYucharReadValueFromBufferListener());
2384                                             break;
2385                                         case PLY_SHORT:
2386                                             property.setReadValueFromBufferListener(
2387                                                     new NYshortReadValueFromBufferListener());
2388                                             break;
2389                                         case PLY_USHORT:
2390                                             property.setReadValueFromBufferListener(
2391                                                     new NYushortReadValueFromBufferListener());
2392                                             break;
2393                                         case PLY_INT:
2394                                             property.setReadValueFromBufferListener(
2395                                                     new NYintReadValueFromBufferListener());
2396                                             break;
2397                                         case PLY_UINT:
2398                                             property.setReadValueFromBufferListener(
2399                                                     new NYuintReadValueFromBufferListener());
2400                                             break;
2401                                         case PLY_FLOAT:
2402                                             property.setReadValueFromBufferListener(
2403                                                     new NYfloatReadValueFromBufferListener());
2404                                             break;
2405                                         case PLY_DOUBLE:
2406                                             property.setReadValueFromBufferListener(
2407                                                     new NYdoubleReadValueFromBufferListener());
2408                                             break;
2409                                         default:
2410                                             throw new LoaderException();
2411                                     }
2412                                     break;
2413                                 case "nz":
2414                                     normalsAvailable = true;
2415                                     switch (property.getValueType()) {
2416                                         case PLY_INT8:
2417                                             property.setReadValueFromBufferListener(
2418                                                     new NZint8ReadValueFromBufferListener());
2419                                             break;
2420                                         case PLY_UINT8:
2421                                             property.setReadValueFromBufferListener(
2422                                                     new NZuint8ReadValueFromBufferListener());
2423                                             break;
2424                                         case PLY_INT16:
2425                                             property.setReadValueFromBufferListener(
2426                                                     new NZint16ReadValueFromBufferListener());
2427                                             break;
2428                                         case PLY_UINT16:
2429                                             property.setReadValueFromBufferListener(
2430                                                     new NZuint16ReadValueFromBufferListener());
2431                                             break;
2432                                         case PLY_INT32:
2433                                             property.setReadValueFromBufferListener(
2434                                                     new NZint32ReadValueFromBufferListener());
2435                                             break;
2436                                         case PLY_UINT32:
2437                                             property.setReadValueFromBufferListener(
2438                                                     new NZuint32ReadValueFromBufferListener());
2439                                             break;
2440                                         case PLY_FLOAT32:
2441                                             property.setReadValueFromBufferListener(
2442                                                     new NZfloat32ReadValueFromBufferListener());
2443                                             break;
2444                                         case PLY_FLOAT64:
2445                                             property.setReadValueFromBufferListener(
2446                                                     new NZfloat64ReadValueFromBufferListener());
2447                                             break;
2448                                         case PLY_CHAR:
2449                                             property.setReadValueFromBufferListener(
2450                                                     new NZcharReadValueFromBufferListener());
2451                                             break;
2452                                         case PLY_UCHAR:
2453                                             property.setReadValueFromBufferListener(
2454                                                     new NZucharReadValueFromBufferListener());
2455                                             break;
2456                                         case PLY_SHORT:
2457                                             property.setReadValueFromBufferListener(
2458                                                     new NZshortReadValueFromBufferListener());
2459                                             break;
2460                                         case PLY_USHORT:
2461                                             property.setReadValueFromBufferListener(
2462                                                     new NZushortReadValueFromBufferListener());
2463                                             break;
2464                                         case PLY_INT:
2465                                             property.setReadValueFromBufferListener(
2466                                                     new NZintReadValueFromBufferListener());
2467                                             break;
2468                                         case PLY_UINT:
2469                                             property.setReadValueFromBufferListener(
2470                                                     new NZuintReadValueFromBufferListener());
2471                                             break;
2472                                         case PLY_FLOAT:
2473                                             property.setReadValueFromBufferListener(
2474                                                     new NZfloatReadValueFromBufferListener());
2475                                             break;
2476                                         case PLY_DOUBLE:
2477                                             property.setReadValueFromBufferListener(
2478                                                     new NZdoubleReadValueFromBufferListener());
2479                                             break;
2480                                         default:
2481                                             throw new LoaderException();
2482                                     }
2483                                     break;
2484                                 case "red":
2485                                     colorsAvailable = true;
2486                                     colorComponents++;
2487                                     switch (property.getValueType()) {
2488                                         case PLY_INT8:
2489                                             property.setReadValueFromBufferListener(
2490                                                     new RedInt8ReadValueFromBufferListener());
2491                                             break;
2492                                         case PLY_UINT8:
2493                                             property.setReadValueFromBufferListener(
2494                                                     new RedUint8ReadValueFromBufferListener());
2495                                             break;
2496                                         case PLY_INT16:
2497                                             property.setReadValueFromBufferListener(
2498                                                     new RedInt16ReadValueFromBufferListener());
2499                                             break;
2500                                         case PLY_UINT16:
2501                                             property.setReadValueFromBufferListener(
2502                                                     new RedUint16ReadValueFromBufferListener());
2503                                             break;
2504                                         case PLY_INT32:
2505                                             property.setReadValueFromBufferListener(
2506                                                     new RedInt32ReadValueFromBufferListener());
2507                                             break;
2508                                         case PLY_UINT32:
2509                                             property.setReadValueFromBufferListener(
2510                                                     new RedUint32ReadValueFromBufferListener());
2511                                             break;
2512                                         case PLY_FLOAT32:
2513                                             property.setReadValueFromBufferListener(
2514                                                     new RedFloat32ReadValueFromBufferListener());
2515                                             break;
2516                                         case PLY_FLOAT64:
2517                                             property.setReadValueFromBufferListener(
2518                                                     new RedFloat64ReadValueFromBufferListener());
2519                                             break;
2520                                         case PLY_CHAR:
2521                                             property.setReadValueFromBufferListener(
2522                                                     new RedCharReadValueFromBufferListener());
2523                                             break;
2524                                         case PLY_UCHAR:
2525                                             property.setReadValueFromBufferListener(
2526                                                     new RedUcharReadValueFromBufferListener());
2527                                             break;
2528                                         case PLY_SHORT:
2529                                             property.setReadValueFromBufferListener(
2530                                                     new RedShortReadValueFromBufferListener());
2531                                             break;
2532                                         case PLY_USHORT:
2533                                             property.setReadValueFromBufferListener(
2534                                                     new RedUshortReadValueFromBufferListener());
2535                                             break;
2536                                         case PLY_INT:
2537                                             property.setReadValueFromBufferListener(
2538                                                     new RedIntReadValueFromBufferListener());
2539                                             break;
2540                                         case PLY_UINT:
2541                                             property.setReadValueFromBufferListener(
2542                                                     new RedUintReadValueFromBufferListener());
2543                                             break;
2544                                         case PLY_FLOAT:
2545                                             property.setReadValueFromBufferListener(
2546                                                     new RedFloatReadValueFromBufferListener());
2547                                             break;
2548                                         case PLY_DOUBLE:
2549                                             property.setReadValueFromBufferListener(
2550                                                     new RedDoubleReadValueFromBufferListener());
2551                                             break;
2552                                         default:
2553                                             throw new LoaderException();
2554                                     }
2555                                     break;
2556                                 case "green":
2557                                     colorsAvailable = true;
2558                                     colorComponents++;
2559                                     switch (property.getValueType()) {
2560                                         case PLY_INT8:
2561                                             property.setReadValueFromBufferListener(
2562                                                     new GreenInt8ReadValueFromBufferListener());
2563                                             break;
2564                                         case PLY_UINT8:
2565                                             property.setReadValueFromBufferListener(
2566                                                     new GreenUint8ReadValueFromBufferListener());
2567                                             break;
2568                                         case PLY_INT16:
2569                                             property.setReadValueFromBufferListener(
2570                                                     new GreenInt16ReadValueFromBufferListener());
2571                                             break;
2572                                         case PLY_UINT16:
2573                                             property.setReadValueFromBufferListener(
2574                                                     new GreenUint16ReadValueFromBufferListener());
2575                                             break;
2576                                         case PLY_INT32:
2577                                             property.setReadValueFromBufferListener(
2578                                                     new GreenInt32ReadValueFromBufferListener());
2579                                             break;
2580                                         case PLY_UINT32:
2581                                             property.setReadValueFromBufferListener(
2582                                                     new GreenUint32ReadValueFromBufferListener());
2583                                             break;
2584                                         case PLY_FLOAT32:
2585                                             property.setReadValueFromBufferListener(
2586                                                     new GreenFloat32ReadValueFromBufferListener());
2587                                             break;
2588                                         case PLY_FLOAT64:
2589                                             property.setReadValueFromBufferListener(
2590                                                     new GreenFloat64ReadValueFromBufferListener());
2591                                             break;
2592                                         case PLY_CHAR:
2593                                             property.setReadValueFromBufferListener(
2594                                                     new GreenCharReadValueFromBufferListener());
2595                                             break;
2596                                         case PLY_UCHAR:
2597                                             property.setReadValueFromBufferListener(
2598                                                     new GreenUcharReadValueFromBufferListener());
2599                                             break;
2600                                         case PLY_SHORT:
2601                                             property.setReadValueFromBufferListener(
2602                                                     new GreenShortReadValueFromBufferListener());
2603                                             break;
2604                                         case PLY_USHORT:
2605                                             property.setReadValueFromBufferListener(
2606                                                     new GreenUshortReadValueFromBufferListener());
2607                                             break;
2608                                         case PLY_INT:
2609                                             property.setReadValueFromBufferListener(
2610                                                     new GreenIntReadValueFromBufferListener());
2611                                             break;
2612                                         case PLY_UINT:
2613                                             property.setReadValueFromBufferListener(
2614                                                     new GreenUintReadValueFromBufferListener());
2615                                             break;
2616                                         case PLY_FLOAT:
2617                                             property.setReadValueFromBufferListener(
2618                                                     new GreenFloatReadValueFromBufferListener());
2619                                             break;
2620                                         case PLY_DOUBLE:
2621                                             property.setReadValueFromBufferListener(
2622                                                     new GreenDoubleReadValueFromBufferListener());
2623                                             break;
2624                                         default:
2625                                             throw new LoaderException();
2626                                     }
2627                                     break;
2628                                 case "blue":
2629                                     colorsAvailable = true;
2630                                     colorComponents++;
2631                                     switch (property.getValueType()) {
2632                                         case PLY_INT8:
2633                                             property.setReadValueFromBufferListener(
2634                                                     new BlueInt8ReadValueFromBufferListener());
2635                                             break;
2636                                         case PLY_UINT8:
2637                                             property.setReadValueFromBufferListener(
2638                                                     new BlueUint8ReadValueFromBufferListener());
2639                                             break;
2640                                         case PLY_INT16:
2641                                             property.setReadValueFromBufferListener(
2642                                                     new BlueInt16ReadValueFromBufferListener());
2643                                             break;
2644                                         case PLY_UINT16:
2645                                             property.setReadValueFromBufferListener(
2646                                                     new BlueUint16ReadValueFromBufferListener());
2647                                             break;
2648                                         case PLY_INT32:
2649                                             property.setReadValueFromBufferListener(
2650                                                     new BlueInt32ReadValueFromBufferListener());
2651                                             break;
2652                                         case PLY_UINT32:
2653                                             property.setReadValueFromBufferListener(
2654                                                     new BlueUint32ReadValueFromBufferListener());
2655                                             break;
2656                                         case PLY_FLOAT32:
2657                                             property.setReadValueFromBufferListener(
2658                                                     new BlueFloat32ReadValueFromBufferListener());
2659                                             break;
2660                                         case PLY_FLOAT64:
2661                                             property.setReadValueFromBufferListener(
2662                                                     new BlueFloat64ReadValueFromBufferListener());
2663                                             break;
2664                                         case PLY_CHAR:
2665                                             property.setReadValueFromBufferListener(
2666                                                     new BlueCharReadValueFromBufferListener());
2667                                             break;
2668                                         case PLY_UCHAR:
2669                                             property.setReadValueFromBufferListener(
2670                                                     new BlueUcharReadValueFromBufferListener());
2671                                             break;
2672                                         case PLY_SHORT:
2673                                             property.setReadValueFromBufferListener(
2674                                                     new BlueShortReadValueFromBufferListener());
2675                                             break;
2676                                         case PLY_USHORT:
2677                                             property.setReadValueFromBufferListener(
2678                                                     new BlueUshortReadValueFromBufferListener());
2679                                             break;
2680                                         case PLY_INT:
2681                                             property.setReadValueFromBufferListener(
2682                                                     new BlueIntReadValueFromBufferListener());
2683                                             break;
2684                                         case PLY_UINT:
2685                                             property.setReadValueFromBufferListener(
2686                                                     new BlueUintReadValueFromBufferListener());
2687                                             break;
2688                                         case PLY_FLOAT:
2689                                             property.setReadValueFromBufferListener(
2690                                                     new BlueFloatReadValueFromBufferListener());
2691                                             break;
2692                                         case PLY_DOUBLE:
2693                                             property.setReadValueFromBufferListener(
2694                                                     new BlueDoubleReadValueFromBufferListener());
2695                                             break;
2696                                         default:
2697                                             throw new LoaderException();
2698                                     }
2699                                     break;
2700                                 case "alpha":
2701                                     colorsAvailable = true;
2702                                     colorComponents++;
2703                                     switch (property.getValueType()) {
2704                                         case PLY_INT8:
2705                                             property.setReadValueFromBufferListener(
2706                                                     new AlphaInt8ReadValueFromBufferListener());
2707                                             break;
2708                                         case PLY_UINT8:
2709                                             property.setReadValueFromBufferListener(
2710                                                     new AlphaUint8ReadValueFromBufferListener());
2711                                             break;
2712                                         case PLY_INT16:
2713                                             property.setReadValueFromBufferListener(
2714                                                     new AlphaInt16ReadValueFromBufferListener());
2715                                             break;
2716                                         case PLY_UINT16:
2717                                             property.setReadValueFromBufferListener(
2718                                                     new AlphaUint16ReadValueFromBufferListener());
2719                                             break;
2720                                         case PLY_INT32:
2721                                             property.setReadValueFromBufferListener(
2722                                                     new AlphaInt32ReadValueFromBufferListener());
2723                                             break;
2724                                         case PLY_UINT32:
2725                                             property.setReadValueFromBufferListener(
2726                                                     new AlphaUint32ReadValueFromBufferListener());
2727                                             break;
2728                                         case PLY_FLOAT32:
2729                                             property.setReadValueFromBufferListener(
2730                                                     new AlphaFloat32ReadValueFromBufferListener());
2731                                             break;
2732                                         case PLY_FLOAT64:
2733                                             property.setReadValueFromBufferListener(
2734                                                     new AlphaFloat64ReadValueFromBufferListener());
2735                                             break;
2736                                         case PLY_CHAR:
2737                                             property.setReadValueFromBufferListener(
2738                                                     new AlphaCharReadValueFromBufferListener());
2739                                             break;
2740                                         case PLY_UCHAR:
2741                                             property.setReadValueFromBufferListener(
2742                                                     new AlphaUcharReadValueFromBufferListener());
2743                                             break;
2744                                         case PLY_SHORT:
2745                                             property.setReadValueFromBufferListener(
2746                                                     new AlphaShortReadValueFromBufferListener());
2747                                             break;
2748                                         case PLY_USHORT:
2749                                             property.setReadValueFromBufferListener(
2750                                                     new AlphaUshortReadValueFromBufferListener());
2751                                             break;
2752                                         case PLY_INT:
2753                                             property.setReadValueFromBufferListener(
2754                                                     new AlphaIntReadValueFromBufferListener());
2755                                             break;
2756                                         case PLY_UINT:
2757                                             property.setReadValueFromBufferListener(
2758                                                     new AlphaUintReadValueFromBufferListener());
2759                                             break;
2760                                         case PLY_FLOAT:
2761                                             property.setReadValueFromBufferListener(
2762                                                     new AlphaFloatReadValueFromBufferListener());
2763                                             break;
2764                                         case PLY_DOUBLE:
2765                                             property.setReadValueFromBufferListener(
2766                                                     new AlphaDoubleReadValueFromBufferListener());
2767                                             break;
2768                                         default:
2769                                             throw new LoaderException();
2770                                     }
2771                                     break;
2772                                 default:
2773                                     // not recognized properties are ignored
2774                                     break;
2775                             }
2776 
2777                             // update vertex data size
2778                             if (loader.header.getStorageMode() != PLYStorageMode.PLY_ASCII) {
2779                                 vertexDataSize += sizeForDataType(property.getValueType());
2780                             }
2781                         }
2782 
2783                         if (loader.header.getStorageMode() != PLYStorageMode.PLY_ASCII
2784                                 && !firstFaceStreamPositionAvailable) {
2785 
2786                             firstVertexStreamPosition = streamPositionOffset;
2787                             firstVertexStreamPositionAvailable = true;
2788                             // update offset taking into account all vertex data
2789                             streamPositionOffset += numberOfVertices * vertexDataSize;
2790                         }
2791 
2792                     } else if ("face".equals(element.getName())) {
2793                         faceElement = element;
2794                         indicesAvailable = true;
2795 
2796                         // obtain number of faces
2797                         numberOfFaces = element.getNumberOfInstances();
2798 
2799                         for (final var property : element.getProperties()) {
2800 
2801                             // set listener to read data from stream
2802                             setReadValueFromStreamListener(property, loader.header.getStorageMode());
2803 
2804                             if (property.getPropertyType() == PropertyTypePLY.PROPERTY_PLY_LIST) {
2805                                 // set listeners to get number of elements in a
2806                                 // list
2807                                 setReadLengthValueFromBufferListener(property);
2808                                 setReadLengthValueFromStreamListener(property, loader.header.getStorageMode());
2809                             }
2810 
2811                             switch (property.getValueType()) {
2812                                 case PLY_INT8:
2813                                     property.setReadValueFromBufferListener(
2814                                             new FaceInt8ReadValueFromBufferListener());
2815                                     break;
2816                                 case PLY_UINT8:
2817                                     property.setReadValueFromBufferListener(
2818                                             new FaceUint8ReadValueFromBufferListener());
2819                                     break;
2820                                 case PLY_INT16:
2821                                     property.setReadValueFromBufferListener(
2822                                             new FaceInt16ReadValueFromBufferListener());
2823                                     break;
2824                                 case PLY_UINT16:
2825                                     property.setReadValueFromBufferListener(
2826                                             new FaceUint16ReadValueFromBufferListener());
2827                                     break;
2828                                 case PLY_INT32:
2829                                     property.setReadValueFromBufferListener(
2830                                             new FaceInt32ReadValueFromBufferListener());
2831                                     break;
2832                                 case PLY_UINT32:
2833                                     property.setReadValueFromBufferListener(
2834                                             new FaceUint32ReadValueFromBufferListener());
2835                                     break;
2836                                 case PLY_FLOAT32:
2837                                     property.setReadValueFromBufferListener(
2838                                             new FaceFloat32ReadValueFromBufferListener());
2839                                     break;
2840                                 case PLY_FLOAT64:
2841                                     property.setReadValueFromBufferListener(
2842                                             new FaceFloat64ReadValueFromBufferListener());
2843                                     break;
2844                                 case PLY_CHAR:
2845                                     property.setReadValueFromBufferListener(
2846                                             new FaceCharReadValueFromBufferListener());
2847                                     break;
2848                                 case PLY_UCHAR:
2849                                     property.setReadValueFromBufferListener(
2850                                             new FaceUcharReadValueFromBufferListener());
2851                                     break;
2852                                 case PLY_SHORT:
2853                                     property.setReadValueFromBufferListener(
2854                                             new FaceShortReadValueFromBufferListener());
2855                                     break;
2856                                 case PLY_USHORT:
2857                                     property.setReadValueFromBufferListener(
2858                                             new FaceUshortReadValueFromBufferListener());
2859                                     break;
2860                                 case PLY_INT:
2861                                     property.setReadValueFromBufferListener(
2862                                             new FaceIntReadValueFromBufferListener());
2863                                     break;
2864                                 case PLY_UINT:
2865                                     property.setReadValueFromBufferListener(
2866                                             new FaceUintReadValueFromBufferListener());
2867                                     break;
2868                                 case PLY_FLOAT:
2869                                     property.setReadValueFromBufferListener(
2870                                             new FaceFloatReadValueFromBufferListener());
2871                                     break;
2872                                 case PLY_DOUBLE:
2873                                     property.setReadValueFromBufferListener(
2874                                             new FaceDoubleReadValueFromBufferListener());
2875                                     break;
2876                                 default:
2877                                     throw new LoaderException();
2878                             }
2879                         }
2880 
2881                         if (loader.header.getStorageMode() != PLYStorageMode.PLY_ASCII) {
2882                             // Binary storage mode (either Little endian or Big
2883                             // endian)
2884                             firstFaceStreamPosition = streamPositionOffset;
2885                             firstFaceStreamPositionAvailable = true;
2886 
2887                             fetchVertexListener = new BinaryVertexFetcherListener();
2888                         } else {
2889                             // ASCII storage mode
2890                             fetchVertexListener = new AsciiVertexFetcherListener();
2891                         }
2892                     }
2893                 }
2894 
2895                 // find first vertex and face positions in stream in case it
2896                 // couldn't be computed
2897                 findFirstVertexAndFaceStreamPosition();
2898 
2899                 // set stream into 1st face position
2900                 if (!firstFaceStreamPositionAvailable) {
2901                     throw new LoaderException();
2902                 }
2903                 reader.seek(firstFaceStreamPosition);
2904                 currentFace = 0;
2905 
2906             } catch (final NotAvailableException e) {
2907                 throw new LoaderException(e);
2908             }
2909         }
2910 
2911         /**
2912          * Returns size in bytes for a given data type.
2913          *
2914          * @param type A data type.
2915          * @return Size in bytes for a given data type.
2916          */
2917         private long sizeForDataType(final DataTypePLY type) {
2918             return switch (type) {
2919                 case PLY_INT8, PLY_UINT8, PLY_CHAR, PLY_UCHAR -> 1; // 1 byte
2920                 case PLY_INT16, PLY_UINT16, PLY_SHORT, PLY_USHORT -> 2; // 2 bytes
2921                 case PLY_INT32, PLY_UINT32, PLY_FLOAT32, PLY_INT, PLY_UINT, PLY_FLOAT -> 4; // 4 bytes
2922                 case PLY_FLOAT64, PLY_DOUBLE -> 8; // 8 bytes
2923             };
2924         }
2925 
2926         /**
2927          * Finds in file stream the location of the first vertex and face.
2928          *
2929          * @throws LoaderException       Raised if file is corrupted and location of
2930          *                               first vertex or face cannot be found.
2931          * @throws NotAvailableException Raised if header does not contain a
2932          *                               given element.
2933          * @throws IOException           if an I/O error occurs.
2934          */
2935         private void findFirstVertexAndFaceStreamPosition() throws LoaderException, NotAvailableException, IOException {
2936 
2937             if (firstVertexStreamPositionAvailable && firstFaceStreamPositionAvailable) {
2938                 // already computed
2939                 return;
2940             }
2941 
2942             final var buffer = ByteBuffer.allocate(BUFFER_SIZE);
2943 
2944             long nElems;
2945             var counter = 0L;
2946 
2947             // iterate over elements in header
2948             for (final var element : loader.header.getElements()) {
2949                 if (!element.isValidElement()) {
2950                     throw new LoaderException();
2951                 }
2952 
2953                 var stop = false;
2954                 if ("vertex".equals(element.getName())) {
2955                     // FIRST VERTEX FOUND!
2956                     firstVertexStreamPosition = reader.getPosition();
2957                     firstVertexStreamPositionAvailable = true;
2958 
2959                     vertexElement = element;
2960 
2961                     // stop if both 1st vertex and face are known
2962                     stop = firstFaceStreamPositionAvailable;
2963                 } else if ("face".equals(element.getName())) {
2964                     // FIRST FACE FOUND!
2965                     firstFaceStreamPosition = reader.getPosition();
2966                     firstFaceStreamPositionAvailable = true;
2967 
2968                     faceElement = element;
2969 
2970                     // stop if both 1st vertex and face are known
2971                     stop = firstVertexStreamPositionAvailable;
2972                 }
2973 
2974                 if (stop) {
2975                     break;
2976                 }
2977 
2978                 nElems = element.getNumberOfInstances();
2979                 // repeat properties iteration for each element
2980                 for (var i = 0L; i < nElems; i++) {
2981 
2982                     PLYReadValueFromStreamListener readLengthValueFromStreamListener;
2983                     PLYReadValueFromBufferListener readLengthValueFromBufferListener;
2984                     PLYReadValueFromStreamListener readValueFromStreamListener;
2985 
2986                     // iterate on properties of element
2987                     for (final var property : element.getProperties()) {
2988                         if (!property.isValidProperty()) {
2989                             throw new LoaderException();
2990                         }
2991 
2992                         // number of elements in list (initially assume that is
2993                         // scalar, hence 1
2994                         listElems = 1;
2995 
2996                         if (property.getPropertyType() == PropertyTypePLY.PROPERTY_PLY_LIST) {
2997                             // read number of list elements
2998                             readLengthValueFromStreamListener = property.getReadLengthValueFromStreamListener();
2999                             readLengthValueFromStreamListener.readFromStream(buffer);
3000 
3001                             if (reader.isEndOfStream() && (counter < (totalInstances - 1))) {
3002                                 throw new LoaderException();
3003                             }
3004 
3005                             readLengthValueFromBufferListener = property.getReadLengthValueFromBufferListener();
3006                             readLengthValueFromBufferListener.readValueFromBuffer(buffer);
3007                         }
3008 
3009                         // set delegate to read from stream
3010                         readValueFromStreamListener = property.getReadValueFromStreamListener();
3011 
3012                         // read property data
3013                         for (var u = 0L; u < listElems; u++) {
3014                             readValueFromStreamListener.readFromStream(buffer);
3015 
3016                             if (reader.isEndOfStream() && (counter < (totalInstances - 1))) {
3017                                 throw new LoaderException();
3018                             }
3019                         }
3020                     }
3021 
3022                     counter++;
3023                 }
3024             }
3025         }
3026 
3027         /**
3028          * Class to fetch vertex position within the file stream for a binary.
3029          * file.
3030          */
3031         private class BinaryVertexFetcherListener implements VertexFetcherListener {
3032 
3033             /**
3034              * Fetches vertex position and sets current stream position to
3035              * desired vertex.
3036              *
3037              * @param index index of vertex to be searched.
3038              * @throws LoaderException if file is corrupted.
3039              * @throws IOException     if an I/O error occurs.
3040              */
3041             @Override
3042             public void fetch(final long index) throws LoaderException, IOException {
3043 
3044                 final var nElems = vertexElement.getNumberOfInstances();
3045                 if (index < 0 || index >= nElems) {
3046                     throw new LoaderException();
3047                 }
3048 
3049                 final var pos = firstVertexStreamPosition + (index * vertexDataSize);
3050                 if (reader.getPosition() != pos) {
3051                     reader.seek(pos);
3052                 }
3053             }
3054         }
3055 
3056         /**
3057          * Class to fetch vertex position within the file stream for an ascii
3058          * file.
3059          */
3060         private class AsciiVertexFetcherListener implements VertexFetcherListener {
3061 
3062             /**
3063              * Fetches vertex position and sets current stream position to
3064              * desired vertex.
3065              *
3066              * @param index index of vertex to be searched.
3067              * @throws LoaderException       if file is corrupted.
3068              * @throws IOException           if an I/O error occurs.
3069              * @throws NotAvailableException if a given element in the header
3070              *                               is not available.
3071              */
3072             @Override
3073             public void fetch(final long index) throws LoaderException, IOException, NotAvailableException {
3074 
3075                 final var nElems = vertexElement.getNumberOfInstances();
3076                 if (index < 0 || index >= nElems) {
3077                     throw new LoaderException();
3078                 }
3079 
3080                 final var fetchBuffer = ByteBuffer.allocate(BUFFER_SIZE);
3081 
3082                 var startStreamPos = firstVertexStreamPosition;
3083                 var startIndex = 0L;
3084 
3085                 if (!verticesStreamPositionsMap.isEmpty()) {
3086                     // with floorEntry, we will pick element immediately
3087                     // before or equal to index if any exists
3088                     final var entry = verticesStreamPositionsMap.floorEntry(index);
3089                     if (entry != null) {
3090                         final var origIndex = entry.getKey();
3091                         final var pos = entry.getValue();
3092                         if ((origIndex <= index) && (pos >= 0)) {
3093                             startIndex = origIndex;
3094                             startStreamPos = pos;
3095                         }
3096                     }
3097                 }
3098 
3099                 // if we need to read next vertex, don't do anything, otherwise
3100                 // move to next vertex location if reading some vertex located
3101                 // further on the stream. For previous vertex indices, start from
3102                 // beginning
3103                 if (reader.getPosition() != startStreamPos) {
3104                     reader.seek(startStreamPos);
3105                 }
3106 
3107                 // read from stream until start of data of desired vertex
3108                 for (var i = startIndex; i < index; i++) {
3109 
3110                     // when traversing stream of data until reaching desired
3111                     // index, we add all vertex positions into map
3112                     final var streamPosition = reader.getPosition();
3113                     addVertexPositionToMap(i, streamPosition);
3114 
3115                     PLYReadValueFromStreamListener readValueFromStreamListener;
3116 
3117                     // iterate on vertex element properties
3118                     for (final var property : vertexElement.getProperties()) {
3119                         if (!property.isValidProperty()) {
3120                             throw new LoaderException();
3121                         }
3122 
3123                         // set delegates to read property value
3124                         readValueFromStreamListener = property.getReadValueFromStreamListener();
3125                         // and read value
3126                         readValueFromStreamListener.readFromStream(fetchBuffer);
3127 
3128                         if (reader.isEndOfStream() && (i < (index - 1))) {
3129                             throw new LoaderException();
3130                         }
3131                     }
3132                 }
3133 
3134                 vertexStreamPosition = reader.getPosition();
3135             }
3136         }
3137 
3138         /**
3139          * Reads x vertex coordinate from temporal buffer using int8 data type.
3140          */
3141         private class Xint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3142 
3143             /**
3144              * Reads x vertex coordinate from temporal buffer and sets its value
3145              * on current loader iterator.
3146              *
3147              * @param buffer Temporal buffer.
3148              */
3149             @Override
3150             public void readValueFromBuffer(final ByteBuffer buffer) {
3151                 loaderIterator.coordX = buffer.get(0);
3152             }
3153         }
3154 
3155         /**
3156          * Reads y vertex coordinate from temporal buffer using int8 data type.
3157          */
3158         private class Yint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3159 
3160             /**
3161              * Reads y vertex coordinate from temporal buffer and sets its value
3162              * on current loader iterator.
3163              *
3164              * @param buffer Temporal buffer.
3165              */
3166             @Override
3167             public void readValueFromBuffer(final ByteBuffer buffer) {
3168                 loaderIterator.coordY = buffer.get(0);
3169             }
3170         }
3171 
3172         /**
3173          * Reads z vertex coordinate from temporal buffer using int8 data type.
3174          */
3175         private class Zint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3176 
3177             /**
3178              * Reads z vertex coordinate from temporal buffer and sets its value
3179              * on current loader iterator.
3180              *
3181              * @param buffer Temporal buffer.
3182              */
3183             @Override
3184             public void readValueFromBuffer(final ByteBuffer buffer) {
3185                 loaderIterator.coordZ = buffer.get(0);
3186             }
3187         }
3188 
3189         /**
3190          * Reads x vertex coordinate from temporal buffer using uint8 data type.
3191          */
3192         private class Xuint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3193 
3194             /**
3195              * Reads x vertex coordinate from temporal buffer and sets its value
3196              * on current loader iterator.
3197              *
3198              * @param buffer Temporal buffer.
3199              */
3200             @Override
3201             public void readValueFromBuffer(final ByteBuffer buffer) {
3202                 // because java doesn't support unsigned types we use the next
3203                 // type that can hold all desired values
3204                 loaderIterator.coordX = buffer.getShort(0);
3205             }
3206         }
3207 
3208         /**
3209          * Reads y vertex coordinate from temporal buffer using uint8 data type.
3210          */
3211         private class Yuint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3212 
3213             /**
3214              * Reads y vertex coordinate from temporal buffer and sets its value
3215              * on current loader iterator.
3216              *
3217              * @param buffer Temporal buffer.
3218              */
3219             @Override
3220             public void readValueFromBuffer(final ByteBuffer buffer) {
3221                 // because java doesn't support unsigned types we use the next
3222                 // type that can hold all desired values
3223                 loaderIterator.coordY = buffer.getShort(0);
3224             }
3225         }
3226 
3227         /**
3228          * Reads z vertex coordinate from temporal buffer using uint8 data type.
3229          */
3230         private class Zuint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3231 
3232             /**
3233              * Reads z vertex coordinate from temporal buffer and sets its value
3234              * on current loader iterator.
3235              *
3236              * @param buffer Temporal buffer.
3237              */
3238             @Override
3239             public void readValueFromBuffer(final ByteBuffer buffer) {
3240                 // because java doesn't support unsigned types we use the next
3241                 // type that can hold all desired values
3242                 loaderIterator.coordZ = buffer.getShort(0);
3243             }
3244         }
3245 
3246         /**
3247          * Reads x vertex coordinate from temporal buffer using int16 data type.
3248          */
3249         private class Xint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3250 
3251             /**
3252              * Reads x vertex coordinate from temporal buffer and sets its value
3253              * on current loader iterator.
3254              *
3255              * @param buffer Temporal buffer.
3256              */
3257             @Override
3258             public void readValueFromBuffer(final ByteBuffer buffer) {
3259                 loaderIterator.coordX = buffer.getShort(0);
3260             }
3261         }
3262 
3263         /**
3264          * Reads y vertex coordinate from temporal buffer using int16 data type.
3265          */
3266         private class Yint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3267 
3268             /**
3269              * Reads y vertex coordinate from temporal buffer and sets its value
3270              * on current loader iterator.
3271              *
3272              * @param buffer Temporal buffer.
3273              */
3274             @Override
3275             public void readValueFromBuffer(final ByteBuffer buffer) {
3276                 loaderIterator.coordY = buffer.getShort(0);
3277             }
3278         }
3279 
3280         /**
3281          * Reads z vertex coordinate from temporal buffer using int16 data type.
3282          */
3283         private class Zint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3284 
3285             /**
3286              * Reads z vertex coordinate from temporal buffer and sets its value
3287              * on current loader iterator.
3288              *
3289              * @param buffer Temporal buffer.
3290              */
3291             @Override
3292             public void readValueFromBuffer(final ByteBuffer buffer) {
3293                 loaderIterator.coordZ = buffer.getShort(0);
3294             }
3295         }
3296 
3297         /**
3298          * Reads x vertex coordinate from temporal buffer using uint16 data
3299          * type.
3300          */
3301         private class Xuint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3302 
3303             /**
3304              * Reads x vertex coordinate from temporal buffer and sets its value
3305              * on current loader iterator.
3306              *
3307              * @param buffer Temporal buffer.
3308              */
3309             @Override
3310             public void readValueFromBuffer(final ByteBuffer buffer) {
3311                 // because java doesn't support unsigned types we use the next
3312                 // type that can hold all desired values
3313                 loaderIterator.coordX = buffer.getInt(0);
3314             }
3315         }
3316 
3317         /**
3318          * Reads y vertex coordinate from temporal buffer using uint16 data
3319          * type.
3320          */
3321         private class Yuint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3322 
3323             /**
3324              * Reads y vertex coordinate from temporal buffer and sets its value
3325              * on current loader iterator.
3326              *
3327              * @param buffer Temporal buffer.
3328              */
3329             @Override
3330             public void readValueFromBuffer(final ByteBuffer buffer) {
3331                 // because java doesn't support unsigned types we use the next
3332                 // type that can hold all desired values
3333                 loaderIterator.coordY = buffer.getInt(0);
3334             }
3335         }
3336 
3337         /**
3338          * Reads z vertex coordinate from temporal buffer using uint16 data
3339          * type.
3340          */
3341         private class Zuint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3342 
3343             /**
3344              * Reads z vertex coordinate from temporal buffer and sets its value
3345              * on current loader iterator.
3346              *
3347              * @param buffer Temporal buffer.
3348              */
3349             @Override
3350             public void readValueFromBuffer(final ByteBuffer buffer) {
3351                 // because java doesn't support unsigned types we use the next
3352                 // type that can hold all desired values
3353                 loaderIterator.coordZ = buffer.getInt(0);
3354             }
3355         }
3356 
3357         /**
3358          * Reads x vertex coordinate from temporal buffer using int32 data type.
3359          */
3360         private class Xint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3361 
3362             /**
3363              * Reads x vertex coordinate from temporal buffer and sets its value
3364              * on current loader iterator.
3365              *
3366              * @param buffer Temporal buffer.
3367              */
3368             @Override
3369             public void readValueFromBuffer(final ByteBuffer buffer) {
3370                 loaderIterator.coordX = buffer.getInt(0);
3371             }
3372         }
3373 
3374         /**
3375          * Reads y vertex coordinate from temporal buffer using int32 data type.
3376          */
3377         private class Yint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3378 
3379             /**
3380              * Reads y vertex coordinate from temporal buffer and sets its value
3381              * on current loader iterator.
3382              *
3383              * @param buffer Temporal buffer.
3384              */
3385             @Override
3386             public void readValueFromBuffer(final ByteBuffer buffer) {
3387                 loaderIterator.coordY = buffer.getInt(0);
3388             }
3389         }
3390 
3391         /**
3392          * Reads z vertex coordinate from temporal buffer using int32 data type.
3393          */
3394         private class Zint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3395 
3396             /**
3397              * Reads z vertex coordinate from temporal buffer and sets its value
3398              * on current loader iterator.
3399              *
3400              * @param buffer Temporal buffer.
3401              */
3402             @Override
3403             public void readValueFromBuffer(final ByteBuffer buffer) {
3404                 loaderIterator.coordZ = buffer.getInt(0);
3405             }
3406         }
3407 
3408         /**
3409          * Reads x vertex coordinate from temporal buffer using uint32 data
3410          * type.
3411          */
3412         private class Xuint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3413 
3414             /**
3415              * Reads x vertex coordinate from temporal buffer and sets its value
3416              * on current loader iterator.
3417              *
3418              * @param buffer Temporal buffer.
3419              */
3420             @Override
3421             public void readValueFromBuffer(final ByteBuffer buffer) {
3422                 // because java doesn't support unsigned types we use the next
3423                 // type that can hold all desired values
3424                 loaderIterator.coordX = buffer.getLong(0);
3425             }
3426         }
3427 
3428         /**
3429          * Reads y vertex coordinate from temporal buffer using uint32 data
3430          * type.
3431          */
3432         private class Yuint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3433 
3434             /**
3435              * Reads y vertex coordinate from temporal buffer and sets its value
3436              * on current loader iterator.
3437              *
3438              * @param buffer Temporal buffer.
3439              */
3440             @Override
3441             public void readValueFromBuffer(final ByteBuffer buffer) {
3442                 // because java doesn't support unsigned types we use the next
3443                 // type that can hold all desired values
3444                 loaderIterator.coordY = buffer.getLong(0);
3445             }
3446         }
3447 
3448         /**
3449          * Reads z vertex coordinate from temporal buffer using uint32 data
3450          * type.
3451          */
3452         private class Zuint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3453 
3454             /**
3455              * Reads z vertex coordinate from temporal buffer and sets its value
3456              * on current loader iterator.
3457              *
3458              * @param buffer Temporal buffer.
3459              */
3460             @Override
3461             public void readValueFromBuffer(final ByteBuffer buffer) {
3462                 // because java doesn't support unsigned types we use the next
3463                 // type that can hold all desired values
3464                 loaderIterator.coordZ = buffer.getLong(0);
3465             }
3466         }
3467 
3468         /**
3469          * Reads x vertex coordinate from temporal buffer using float32 data
3470          * type.
3471          */
3472         private class Xfloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3473 
3474             /**
3475              * Reads x vertex coordinate from temporal buffer and sets its value
3476              * on current loader iterator.
3477              *
3478              * @param buffer Temporal buffer.
3479              */
3480             @Override
3481             public void readValueFromBuffer(final ByteBuffer buffer) {
3482                 loaderIterator.coordX = buffer.getFloat(0);
3483             }
3484         }
3485 
3486         /**
3487          * Reads y vertex coordinate from temporal buffer using float32 data
3488          * type.
3489          */
3490         private class Yfloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3491 
3492             /**
3493              * Reads y vertex coordinate from temporal buffer and sets its value
3494              * on current loader iterator.
3495              *
3496              * @param buffer Temporal buffer.
3497              */
3498             @Override
3499             public void readValueFromBuffer(final ByteBuffer buffer) {
3500                 loaderIterator.coordY = buffer.getFloat(0);
3501             }
3502         }
3503 
3504         /**
3505          * Reads z vertex coordinate from temporal buffer using float32 data
3506          * type.
3507          */
3508         private class Zfloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3509 
3510             /**
3511              * Reads z vertex coordinate from temporal buffer and sets its value
3512              * on current loader iterator.
3513              *
3514              * @param buffer Temporal buffer.
3515              */
3516             @Override
3517             public void readValueFromBuffer(final ByteBuffer buffer) {
3518                 loaderIterator.coordZ = buffer.getFloat(0);
3519             }
3520         }
3521 
3522         /**
3523          * Reads x vertex coordinate from temporal buffer using float64 data
3524          * type.
3525          */
3526         private class Xfloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3527 
3528             /**
3529              * Reads x vertex coordinate from temporal buffer and sets its value
3530              * on current loader iterator.
3531              *
3532              * @param buffer Temporal buffer.
3533              */
3534             @Override
3535             public void readValueFromBuffer(final ByteBuffer buffer) {
3536                 final var value = buffer.getDouble(0);
3537 
3538                 loaderIterator.coordX = (float) value;
3539             }
3540         }
3541 
3542         /**
3543          * Reads y vertex coordinate from temporal buffer using float64 data
3544          * type.
3545          */
3546         private class Yfloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3547 
3548             /**
3549              * Reads y vertex coordinate from temporal buffer and sets its value
3550              * on current loader iterator.
3551              *
3552              * @param buffer Temporal buffer.
3553              */
3554             @Override
3555             public void readValueFromBuffer(final ByteBuffer buffer) {
3556                 final var value = buffer.getDouble(0);
3557 
3558                 loaderIterator.coordY = (float) value;
3559             }
3560         }
3561 
3562         /**
3563          * Reads z vertex coordinate from temporal buffer using float64 data
3564          * type.
3565          */
3566         private class Zfloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3567 
3568             /**
3569              * Reads z vertex coordinate from temporal buffer and sets its value
3570              * on current loader iterator.
3571              *
3572              * @param buffer Temporal buffer.
3573              */
3574             @Override
3575             public void readValueFromBuffer(final ByteBuffer buffer) {
3576                 final var value = buffer.getDouble(0);
3577 
3578                 loaderIterator.coordZ = (float) value;
3579             }
3580         }
3581 
3582         /**
3583          * Reads x vertex coordinate from temporal buffer using char data type.
3584          */
3585         private class XcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3586 
3587             /**
3588              * Reads x vertex coordinate from temporal buffer and sets its value
3589              * on current loader iterator.
3590              *
3591              * @param buffer Temporal buffer.
3592              */
3593             @Override
3594             public void readValueFromBuffer(final ByteBuffer buffer) {
3595                 loaderIterator.coordX = buffer.get(0);
3596             }
3597         }
3598 
3599         /**
3600          * Reads y vertex coordinate from temporal buffer using char data type.
3601          */
3602         private class YcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3603 
3604             /**
3605              * Reads y vertex coordinate from temporal buffer and sets its value
3606              * on current loader iterator.
3607              *
3608              * @param buffer Temporal buffer.
3609              */
3610             @Override
3611             public void readValueFromBuffer(final ByteBuffer buffer) {
3612                 loaderIterator.coordY = buffer.get(0);
3613             }
3614         }
3615 
3616         /**
3617          * Reads z vertex coordinate from temporal buffer using char data type.
3618          */
3619         private class ZcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3620 
3621             /**
3622              * Reads z vertex coordinate from temporal buffer and sets its value
3623              * on current loader iterator.
3624              *
3625              * @param buffer Temporal buffer.
3626              */
3627             @Override
3628             public void readValueFromBuffer(final ByteBuffer buffer) {
3629                 loaderIterator.coordZ = buffer.get(0);
3630             }
3631         }
3632 
3633         /**
3634          * Reads x vertex coordinate from temporal buffer using uchar data type.
3635          */
3636         private class XucharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3637 
3638             /**
3639              * Reads x vertex coordinate from temporal buffer and sets its value
3640              * on current loader iterator.
3641              *
3642              * @param buffer Temporal buffer.
3643              */
3644             @Override
3645             public void readValueFromBuffer(final ByteBuffer buffer) {
3646                 // because java doesn't support unsigned types we use the next
3647                 // type that can hold all desired values
3648                 loaderIterator.coordX = buffer.getShort(0);
3649             }
3650         }
3651 
3652         /**
3653          * Reads y vertex coordinate from temporal buffer using uchar data type.
3654          */
3655         private class YucharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3656 
3657             /**
3658              * Reads y vertex coordinate from temporal buffer and sets its value
3659              * on current loader iterator.
3660              *
3661              * @param buffer Temporal buffer.
3662              */
3663             @Override
3664             public void readValueFromBuffer(final ByteBuffer buffer) {
3665                 // because java doesn't support unsigned types we use the next
3666                 // type that can hold all desired values
3667                 loaderIterator.coordY = buffer.getShort(0);
3668             }
3669         }
3670 
3671         /**
3672          * Reads z vertex coordinate from temporal buffer using uchar data type.
3673          */
3674         private class ZucharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3675 
3676             /**
3677              * Reads z vertex coordinate from temporal buffer and sets its value
3678              * on current loader iterator.
3679              *
3680              * @param buffer Temporal buffer.
3681              */
3682             @Override
3683             public void readValueFromBuffer(final ByteBuffer buffer) {
3684                 // because java doesn't support unsigned types we use the next
3685                 // type that can hold all desired values
3686                 loaderIterator.coordZ = buffer.getShort(0);
3687             }
3688         }
3689 
3690         /**
3691          * Reads x vertex coordinate from temporal buffer using short data type.
3692          */
3693         private class XshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3694 
3695             /**
3696              * Reads x vertex coordinate from temporal buffer and sets its value
3697              * on current loader iterator.
3698              *
3699              * @param buffer Temporal buffer.
3700              */
3701             @Override
3702             public void readValueFromBuffer(final ByteBuffer buffer) {
3703                 loaderIterator.coordX = buffer.getShort(0);
3704             }
3705         }
3706 
3707         /**
3708          * Reads y vertex coordinate from temporal buffer using short data type.
3709          */
3710         private class YshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3711 
3712             /**
3713              * Reads y vertex coordinate from temporal buffer and sets its value
3714              * on current loader iterator.
3715              *
3716              * @param buffer Temporal buffer.
3717              */
3718             @Override
3719             public void readValueFromBuffer(final ByteBuffer buffer) {
3720                 loaderIterator.coordY = buffer.getShort(0);
3721             }
3722         }
3723 
3724         /**
3725          * Reads z vertex coordinate from temporal buffer using short data type.
3726          */
3727         private class ZshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3728 
3729             /**
3730              * Reads z vertex coordinate from temporal buffer and sets its value
3731              * on current loader iterator.
3732              *
3733              * @param buffer Temporal buffer.
3734              */
3735             @Override
3736             public void readValueFromBuffer(final ByteBuffer buffer) {
3737                 loaderIterator.coordZ = buffer.getShort(0);
3738             }
3739         }
3740 
3741         /**
3742          * Reads x vertex coordinate from temporal buffer using ushort data
3743          * type.
3744          */
3745         private class XushortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3746 
3747             /**
3748              * Reads x vertex coordinate from temporal buffer and sets its value
3749              * on current loader iterator.
3750              *
3751              * @param buffer Temporal buffer.
3752              */
3753             @Override
3754             public void readValueFromBuffer(final ByteBuffer buffer) {
3755                 // because java doesn't support unsigned types we use the next
3756                 // type that can hold all desired values
3757                 loaderIterator.coordX = buffer.getInt(0);
3758             }
3759         }
3760 
3761         /**
3762          * Reads y vertex coordinate from temporal buffer using ushort data
3763          * type.
3764          */
3765         private class YushortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3766 
3767             /**
3768              * Reads y vertex coordinate from temporal buffer and sets its value
3769              * on current loader iterator.
3770              *
3771              * @param buffer Temporal buffer.
3772              */
3773             @Override
3774             public void readValueFromBuffer(final ByteBuffer buffer) {
3775                 // because java doesn't support unsigned types we use the next
3776                 // type that can hold all desired values
3777                 loaderIterator.coordY = buffer.getInt(0);
3778             }
3779         }
3780 
3781         /**
3782          * Reads z vertex coordinate from temporal buffer using ushort data
3783          * type.
3784          */
3785         private class ZushortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3786 
3787             /**
3788              * Reads z vertex coordinate from temporal buffer and sets its value
3789              * on current loader iterator.
3790              *
3791              * @param buffer Temporal buffer.
3792              */
3793             @Override
3794             public void readValueFromBuffer(final ByteBuffer buffer) {
3795                 // because java doesn't support unsigned types we use the next
3796                 // type that can hold all desired values
3797                 loaderIterator.coordZ = buffer.getInt(0);
3798             }
3799         }
3800 
3801         /**
3802          * Reads x vertex coordinate from temporal buffer using int data type.
3803          */
3804         private class XintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3805 
3806             /**
3807              * Reads x vertex coordinate from temporal buffer and sets its value
3808              * on current loader iterator.
3809              *
3810              * @param buffer Temporal buffer.
3811              */
3812             @Override
3813             public void readValueFromBuffer(final ByteBuffer buffer) {
3814                 loaderIterator.coordX = buffer.getInt(0);
3815             }
3816         }
3817 
3818         /**
3819          * Reads y vertex coordinate from temporal buffer using int data type.
3820          */
3821         private class YintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3822 
3823             /**
3824              * Reads y vertex coordinate from temporal buffer and sets its value
3825              * on current loader iterator.
3826              *
3827              * @param buffer Temporal buffer.
3828              */
3829             @Override
3830             public void readValueFromBuffer(final ByteBuffer buffer) {
3831                 loaderIterator.coordY = buffer.getInt(0);
3832             }
3833         }
3834 
3835         /**
3836          * Reads z vertex coordinate from temporal buffer using int data type.
3837          */
3838         private class ZintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3839 
3840             /**
3841              * Reads z vertex coordinate from temporal buffer and sets its value
3842              * on current loader iterator.
3843              *
3844              * @param buffer Temporal buffer.
3845              */
3846             @Override
3847             public void readValueFromBuffer(final ByteBuffer buffer) {
3848                 loaderIterator.coordZ = buffer.getInt(0);
3849             }
3850         }
3851 
3852         /**
3853          * Reads x vertex coordinate from temporal buffer using uint data type.
3854          */
3855         private class XuintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3856 
3857             /**
3858              * Reads x vertex coordinate from temporal buffer and sets its value
3859              * on current loader iterator.
3860              *
3861              * @param buffer Temporal buffer.
3862              */
3863             @Override
3864             public void readValueFromBuffer(final ByteBuffer buffer) {
3865                 // because java doesn't support unsigned types we use the next
3866                 // type that can hold all desired values
3867                 loaderIterator.coordX = buffer.getLong(0);
3868             }
3869         }
3870 
3871         /**
3872          * Reads y vertex coordinate from temporal buffer using uint data type.
3873          */
3874         private class YuintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3875 
3876             /**
3877              * Reads y vertex coordinate from temporal buffer and sets its value
3878              * on current loader iterator.
3879              *
3880              * @param buffer Temporal buffer.
3881              */
3882             @Override
3883             public void readValueFromBuffer(final ByteBuffer buffer) {
3884                 // because java doesn't support unsigned types we use the next
3885                 // type that can hold all desired values
3886                 loaderIterator.coordY = buffer.getLong(0);
3887             }
3888         }
3889 
3890         /**
3891          * Reads z vertex coordinate from temporal buffer using uint data type.
3892          */
3893         private class ZuintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3894 
3895             /**
3896              * Reads z vertex coordinate from temporal buffer and sets its value
3897              * on current loader iterator.
3898              *
3899              * @param buffer Temporal buffer.
3900              */
3901             @Override
3902             public void readValueFromBuffer(final ByteBuffer buffer) {
3903                 // because java doesn't support unsigned types we use the next
3904                 // type that can hold all desired values
3905                 loaderIterator.coordZ = buffer.getLong(0);
3906             }
3907         }
3908 
3909         /**
3910          * Reads x vertex coordinate from temporal buffer using float data type.
3911          */
3912         private class XfloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3913 
3914             /**
3915              * Reads x vertex coordinate from temporal buffer and sets its value
3916              * on current loader iterator.
3917              *
3918              * @param buffer Temporal buffer.
3919              */
3920             @Override
3921             public void readValueFromBuffer(final ByteBuffer buffer) {
3922                 loaderIterator.coordX = buffer.getFloat(0);
3923             }
3924         }
3925 
3926         /**
3927          * Reads y vertex coordinate from temporal buffer using float data type.
3928          */
3929         private class YfloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3930 
3931             /**
3932              * Reads y vertex coordinate from temporal buffer and sets its value
3933              * on current loader iterator.
3934              *
3935              * @param buffer Temporal buffer.
3936              */
3937             @Override
3938             public void readValueFromBuffer(final ByteBuffer buffer) {
3939                 loaderIterator.coordY = buffer.getFloat(0);
3940             }
3941         }
3942 
3943         /**
3944          * Reads z vertex coordinate from temporal buffer using float data type.
3945          */
3946         private class ZfloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3947 
3948             /**
3949              * Reads z vertex coordinate from temporal buffer and sets its value
3950              * on current loader iterator.
3951              *
3952              * @param buffer Temporal buffer.
3953              */
3954             @Override
3955             public void readValueFromBuffer(final ByteBuffer buffer) {
3956                 loaderIterator.coordZ = buffer.getFloat(0);
3957             }
3958         }
3959 
3960         /**
3961          * Reads x vertex coordinate from temporal buffer using double data
3962          * type.
3963          */
3964         private class XdoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3965 
3966             /**
3967              * Reads x vertex coordinate from temporal buffer and sets its value
3968              * on current loader iterator.
3969              *
3970              * @param buffer Temporal buffer.
3971              */
3972             @Override
3973             public void readValueFromBuffer(final ByteBuffer buffer) {
3974                 final var value = buffer.getDouble(0);
3975 
3976                 loaderIterator.coordX = (float) value;
3977             }
3978         }
3979 
3980         /**
3981          * Reads y vertex coordinate from temporal buffer using double data
3982          * type.
3983          */
3984         private class YdoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
3985 
3986             /**
3987              * Reads y vertex coordinate from temporal buffer and sets its value
3988              * on current loader iterator.
3989              *
3990              * @param buffer Temporal buffer.
3991              */
3992             @Override
3993             public void readValueFromBuffer(final ByteBuffer buffer) {
3994                 final var value = buffer.getDouble(0);
3995 
3996                 loaderIterator.coordY = (float) value;
3997             }
3998         }
3999 
4000         /**
4001          * Reads z vertex coordinate from temporal buffer using double data
4002          * type.
4003          */
4004         private class ZdoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4005 
4006             /**
4007              * Reads z vertex coordinate from temporal buffer and sets its value
4008              * on current loader iterator.
4009              *
4010              * @param buffer Temporal buffer.
4011              */
4012             @Override
4013             public void readValueFromBuffer(final ByteBuffer buffer) {
4014                 final var value = buffer.getDouble(0);
4015 
4016                 loaderIterator.coordZ = (float) value;
4017             }
4018         }
4019 
4020         /**
4021          * Reads red color component from temporal buffer using int8 data type.
4022          */
4023         private class RedInt8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4024 
4025             /**
4026              * Reads red color component from temporal buffer and sets its value
4027              * on current loader iterator.
4028              *
4029              * @param buffer Temporal buffer.
4030              */
4031             @Override
4032             public void readValueFromBuffer(final ByteBuffer buffer) {
4033                 loaderIterator.red = buffer.get(0);
4034             }
4035         }
4036 
4037         /**
4038          * Reads green color component from temporal buffer using int8 data
4039          * type.
4040          */
4041         private class GreenInt8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4042 
4043             /**
4044              * Reads green color component from temporal buffer and sets its
4045              * value on current loader iterator.
4046              *
4047              * @param buffer Temporal buffer.
4048              */
4049             @Override
4050             public void readValueFromBuffer(final ByteBuffer buffer) {
4051                 loaderIterator.green = buffer.get(0);
4052             }
4053         }
4054 
4055         /**
4056          * Reads blue color component from temporal buffer using int8 data type.
4057          */
4058         private class BlueInt8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4059 
4060             /**
4061              * Reads blue color component from temporal buffer and sets its
4062              * value on current loader iterator.
4063              *
4064              * @param buffer Temporal buffer.
4065              */
4066             @Override
4067             public void readValueFromBuffer(final ByteBuffer buffer) {
4068                 loaderIterator.blue = buffer.get(0);
4069             }
4070         }
4071 
4072         /**
4073          * Reads alpha color component from temporal buffer using int8 data
4074          * type.
4075          */
4076         private class AlphaInt8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4077 
4078             /**
4079              * Reads alpha color component from temporal buffer and sets its
4080              * value on current loader iterator.
4081              *
4082              * @param buffer Temporal buffer.
4083              */
4084             @Override
4085             public void readValueFromBuffer(final ByteBuffer buffer) {
4086                 loaderIterator.alpha = buffer.get(0);
4087             }
4088         }
4089 
4090         /**
4091          * Reads red color component from temporal buffer using uint8 data type.
4092          */
4093         private class RedUint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4094 
4095             /**
4096              * Reads red color component from temporal buffer and sets its value
4097              * on current loader iterator.
4098              *
4099              * @param buffer Temporal buffer.
4100              */
4101             @Override
4102             public void readValueFromBuffer(final ByteBuffer buffer) {
4103                 // because java doesn't support unsigned types we use the next
4104                 // type that can hold all desired values
4105                 loaderIterator.red = buffer.getShort(0);
4106             }
4107         }
4108 
4109         /**
4110          * Read green color component from temporal buffer using uint8 data
4111          * type.
4112          */
4113         private class GreenUint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4114 
4115             /**
4116              * Reads green color component from temporal buffer and sets its
4117              * value on current loader iterator.
4118              *
4119              * @param buffer Temporal buffer.
4120              */
4121             @Override
4122             public void readValueFromBuffer(final ByteBuffer buffer) {
4123                 // because java doesn't support unsigned types we use the next
4124                 // type that can hold all desired values
4125                 loaderIterator.green = buffer.getShort(0);
4126             }
4127         }
4128 
4129         /**
4130          * Reads blue color component from temporal buffer using uint8 data
4131          * type.
4132          */
4133         private class BlueUint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4134 
4135             /**
4136              * Reads blue color component from temporal buffer and sets its
4137              * value on current loader iterator.
4138              *
4139              * @param buffer Temporal buffer.
4140              */
4141             @Override
4142             public void readValueFromBuffer(final ByteBuffer buffer) {
4143                 // because java doesn't support unsigned types we use the next
4144                 // type that can hold all desired values
4145                 loaderIterator.blue = buffer.getShort(0);
4146             }
4147         }
4148 
4149         /**
4150          * Reads alpha color component from temporal buffer using uint8 data
4151          * type.
4152          */
4153         private class AlphaUint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4154 
4155             /**
4156              * Reads alpha color component from temporal buffer and sets its
4157              * value on current loader iterator.
4158              *
4159              * @param buffer Temporal buffer.
4160              */
4161             @Override
4162             public void readValueFromBuffer(final ByteBuffer buffer) {
4163                 // because java doesn't support unsigned types we use the next
4164                 // type that can hold all desired values
4165                 loaderIterator.alpha = buffer.getShort(0);
4166             }
4167         }
4168 
4169         /**
4170          * Reads red color component from temporal buffer using int16 data type.
4171          */
4172         private class RedInt16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4173 
4174             /**
4175              * Reads red color component from temporal buffer and sets its value
4176              * on current loader iterator.
4177              *
4178              * @param buffer Temporal buffer.
4179              */
4180             @Override
4181             public void readValueFromBuffer(final ByteBuffer buffer) {
4182                 loaderIterator.red = buffer.getShort(0);
4183             }
4184         }
4185 
4186         /**
4187          * Reads green color component from temporal buffer using int16 data
4188          * type.
4189          */
4190         private class GreenInt16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4191 
4192             /**
4193              * Reads green color component from temporal buffer and sets its
4194              * value on current loader iterator.
4195              *
4196              * @param buffer Temporal buffer.
4197              */
4198             @Override
4199             public void readValueFromBuffer(final ByteBuffer buffer) {
4200                 loaderIterator.green = buffer.getShort(0);
4201             }
4202         }
4203 
4204         /**
4205          * Reads blue color component from temporal buffer using int16 data
4206          * type.
4207          */
4208         private class BlueInt16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4209 
4210             /**
4211              * Reads blue color component from temporal buffer and sets its
4212              * value on current loader iterator.
4213              *
4214              * @param buffer Temporal buffer.
4215              */
4216             @Override
4217             public void readValueFromBuffer(final ByteBuffer buffer) {
4218                 loaderIterator.blue = buffer.getShort(0);
4219             }
4220         }
4221 
4222         /**
4223          * Reads alpha color component from temporal buffer using int16 data
4224          * type.
4225          */
4226         private class AlphaInt16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4227 
4228             /**
4229              * Reads alpha color component from temporal buffer and sets its
4230              * value on current loader iterator.
4231              *
4232              * @param buffer Temporal buffer.
4233              */
4234             @Override
4235             public void readValueFromBuffer(final ByteBuffer buffer) {
4236                 loaderIterator.alpha = buffer.getShort(0);
4237             }
4238         }
4239 
4240         /**
4241          * Reads red color component from temporal buffer using uint16 data
4242          * type.
4243          */
4244         private class RedUint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4245 
4246             /**
4247              * Reads red color component from temporal buffer and sets its value
4248              * on current loader iterator.
4249              *
4250              * @param buffer Temporal buffer.
4251              */
4252             @Override
4253             public void readValueFromBuffer(final ByteBuffer buffer) {
4254                 // because java doesn't support unsigned types we use the next
4255                 // type that can hold all desired values
4256                 final var value = buffer.getInt(0);
4257 
4258                 loaderIterator.red = (short) value;
4259             }
4260         }
4261 
4262         /**
4263          * Reads green color component from temporal buffer using uint16 data
4264          * type.
4265          */
4266         private class GreenUint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4267 
4268             /**
4269              * Reads green color component from temporal buffer and sets its
4270              * value on current loader iterator.
4271              *
4272              * @param buffer Temporal buffer.
4273              */
4274             @Override
4275             public void readValueFromBuffer(final ByteBuffer buffer) {
4276                 // because java doesn't support unsigned types we use the next
4277                 // type that can hold all desired values
4278                 final var value = buffer.getInt(0);
4279 
4280                 loaderIterator.green = (short) value;
4281             }
4282         }
4283 
4284         /**
4285          * Reads blue color component from temporal buffer using uint16 data
4286          * type.
4287          */
4288         private class BlueUint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4289 
4290             /**
4291              * Reads blue color component from temporal buffer and sets its
4292              * value on current loader iterator.
4293              *
4294              * @param buffer Temporal buffer.
4295              */
4296             @Override
4297             public void readValueFromBuffer(final ByteBuffer buffer) {
4298                 // because java doesn't support unsigned types we use the next
4299                 // type that can hold all desired values
4300                 final var value = buffer.getInt(0);
4301 
4302                 loaderIterator.blue = (short) value;
4303             }
4304         }
4305 
4306         /**
4307          * Reads alpha color component from temporal buffer using uint16 data
4308          * type.
4309          */
4310         private class AlphaUint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4311 
4312             /**
4313              * Reads alpha color component from temporal buffer and sets its
4314              * value on current loader iterator.
4315              *
4316              * @param buffer Temporal buffer.
4317              */
4318             @Override
4319             public void readValueFromBuffer(final ByteBuffer buffer) {
4320                 // because java doesn't support unsigned types we use the next
4321                 // type that can hold all desired values
4322                 final var value = buffer.getInt(0);
4323 
4324                 loaderIterator.alpha = (short) value;
4325             }
4326         }
4327 
4328         /**
4329          * Reads red color component from temporal buffer using int32 data type.
4330          */
4331         private class RedInt32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4332 
4333             /**
4334              * Reads red color component from temporal buffer and sets its
4335              * value on current loader iterator.
4336              *
4337              * @param buffer Temporal buffer.
4338              */
4339             @Override
4340             public void readValueFromBuffer(final ByteBuffer buffer) {
4341                 final var value = buffer.getInt(0);
4342 
4343                 loaderIterator.red = (short) value;
4344             }
4345         }
4346 
4347         /**
4348          * Reads green color component from temporal buffer using int32 data
4349          * type.
4350          */
4351         private class GreenInt32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4352 
4353             /**
4354              * Reads green color component from temporal buffer and sets its
4355              * value on current loader iterator.
4356              *
4357              * @param buffer Temporal buffer.
4358              */
4359             @Override
4360             public void readValueFromBuffer(final ByteBuffer buffer) {
4361                 final var value = buffer.getInt(0);
4362 
4363                 loaderIterator.green = (short) value;
4364             }
4365         }
4366 
4367         /**
4368          * Reads blue color component from temporal buffer using int32 data
4369          * type.
4370          */
4371         private class BlueInt32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4372 
4373             /**
4374              * Reads blue color component from temporal buffer and sets its
4375              * value on current loader iterator.
4376              *
4377              * @param buffer Temporal buffer.
4378              */
4379             @Override
4380             public void readValueFromBuffer(final ByteBuffer buffer) {
4381                 final var value = buffer.getInt(0);
4382 
4383                 loaderIterator.blue = (short) value;
4384             }
4385         }
4386 
4387         /**
4388          * Reads alpha color component from temporal buffer using int32 data
4389          * type.
4390          */
4391         private class AlphaInt32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4392 
4393             /**
4394              * Reads alpha color component from temporal buffer and sets its
4395              * value on current loader iterator.
4396              *
4397              * @param buffer Temporal buffer.
4398              */
4399             @Override
4400             public void readValueFromBuffer(final ByteBuffer buffer) {
4401                 final var value = buffer.getInt(0);
4402 
4403                 loaderIterator.alpha = (short) value;
4404             }
4405         }
4406 
4407         /**
4408          * Reads red color component from temporal buffer using uint32 data
4409          * type.
4410          */
4411         private class RedUint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4412 
4413             /**
4414              * Reads red color component from temporal buffer and sets its value
4415              * on current loader iterator.
4416              *
4417              * @param buffer Temporal buffer.
4418              */
4419             @Override
4420             public void readValueFromBuffer(final ByteBuffer buffer) {
4421                 // because java doesn't support unsigned types we use the next
4422                 // type that can hold all desired values
4423                 final var value = buffer.getLong(0);
4424 
4425                 loaderIterator.red = (short) value;
4426             }
4427         }
4428 
4429         /**
4430          * Reads green color component from temporal buffer using uint32 data
4431          * type.
4432          */
4433         private class GreenUint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4434 
4435             /**
4436              * Reads green color component from temporal buffer and sets its
4437              * value on current loader iterator.
4438              *
4439              * @param buffer Temporal buffer.
4440              */
4441             @Override
4442             public void readValueFromBuffer(final ByteBuffer buffer) {
4443                 // because java doesn't support unsigned types we use the next
4444                 // type that can hold all desired values
4445                 final var value = buffer.getLong(0);
4446 
4447                 loaderIterator.green = (short) value;
4448             }
4449         }
4450 
4451         /**
4452          * Reads blue color component from temporal buffer using uint32 data
4453          * type.
4454          */
4455         private class BlueUint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4456 
4457             /**
4458              * Reads blue color component from temporal buffer and sets its
4459              * value on current loader iterator.
4460              *
4461              * @param buffer Temporal buffer.
4462              */
4463             @Override
4464             public void readValueFromBuffer(final ByteBuffer buffer) {
4465                 // because java doesn't support unsigned types we use the next
4466                 // type that can hold all desired values
4467                 final var value = buffer.getLong(0);
4468 
4469                 loaderIterator.blue = (short) value;
4470             }
4471         }
4472 
4473         /**
4474          * Reads alpha color component from temporal buffer using uint32 data
4475          * type.
4476          */
4477         private class AlphaUint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4478 
4479             /**
4480              * Reads alpha color component from temporal buffer and sets its
4481              * value on current loader iterator.
4482              *
4483              * @param buffer Temporal buffer.
4484              */
4485             @Override
4486             public void readValueFromBuffer(final ByteBuffer buffer) {
4487                 // because java doesn't support unsigned types we use the next
4488                 // type that can hold all desired values
4489                 final var value = buffer.getLong(0);
4490 
4491                 loaderIterator.alpha = (short) value;
4492             }
4493         }
4494 
4495         /**
4496          * Reads red color component from temporal buffer using float32 data
4497          * type.
4498          */
4499         private class RedFloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4500 
4501             /**
4502              * Reads red color component from temporal buffer and sets its value
4503              * on current loader iterator.
4504              *
4505              * @param buffer Temporal buffer.
4506              */
4507             @Override
4508             public void readValueFromBuffer(final ByteBuffer buffer) {
4509                 final var value = buffer.getFloat(0);
4510 
4511                 loaderIterator.red = (short) value;
4512             }
4513         }
4514 
4515         /**
4516          * Reads green color component from temporal buffer using float32 data
4517          * type.
4518          */
4519         private class GreenFloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4520 
4521             /**
4522              * Reads green color component from temporal buffer and sets its
4523              * value on current loader iterator.
4524              *
4525              * @param buffer Temporal buffer.
4526              */
4527             @Override
4528             public void readValueFromBuffer(final ByteBuffer buffer) {
4529                 final var value = buffer.getFloat(0);
4530 
4531                 loaderIterator.green = (short) value;
4532             }
4533         }
4534 
4535         /**
4536          * Reads blue color component from temporal buffer using float32 data
4537          * type.
4538          */
4539         private class BlueFloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4540 
4541             /**
4542              * Reads blue color component from temporal buffer and sets its
4543              * value on current loader iterator.
4544              *
4545              * @param buffer Temporal buffer.
4546              */
4547             @Override
4548             public void readValueFromBuffer(final ByteBuffer buffer) {
4549                 final var value = buffer.getFloat(0);
4550 
4551                 loaderIterator.blue = (short) value;
4552             }
4553         }
4554 
4555         /**
4556          * Reads alpha color component from temporal buffer using float32 data
4557          * type.
4558          */
4559         private class AlphaFloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4560 
4561             /**
4562              * Reads alpha color component from temporal buffer and sets its
4563              * value on current loader iterator.
4564              *
4565              * @param buffer Temporal buffer.
4566              */
4567             @Override
4568             public void readValueFromBuffer(final ByteBuffer buffer) {
4569                 final var value = buffer.getFloat(0);
4570 
4571                 loaderIterator.alpha = (short) value;
4572             }
4573         }
4574 
4575         /**
4576          * Reads red color component from temporal buffer using float64 data
4577          * type.
4578          */
4579         private class RedFloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4580 
4581             /**
4582              * Reads red color component from temporal buffer and sets its
4583              * value on current loader iterator.
4584              *
4585              * @param buffer Temporal buffer.
4586              */
4587             @Override
4588             public void readValueFromBuffer(final ByteBuffer buffer) {
4589                 final var value = buffer.getDouble(0);
4590 
4591                 loaderIterator.red = (short) value;
4592             }
4593         }
4594 
4595         /**
4596          * Reads green color component from temporal buffer using float64 data
4597          * type.
4598          */
4599         private class GreenFloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4600 
4601             /**
4602              * Reads green color component from temporal buffer and sets its
4603              * value on current loader iterator.
4604              *
4605              * @param buffer Temporal buffer.
4606              */
4607             @Override
4608             public void readValueFromBuffer(final ByteBuffer buffer) {
4609                 final var value = buffer.getDouble(0);
4610 
4611                 loaderIterator.green = (short) value;
4612             }
4613         }
4614 
4615         /**
4616          * Reads blue color component from temporal buffer using float64 data
4617          * type.
4618          */
4619         private class BlueFloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4620 
4621             /**
4622              * Reads blue color component from temporal buffer and sets its
4623              * value on current loader iterator.
4624              *
4625              * @param buffer Temporal buffer.
4626              */
4627             @Override
4628             public void readValueFromBuffer(final ByteBuffer buffer) {
4629                 final var value = buffer.getDouble(0);
4630 
4631                 loaderIterator.blue = (short) value;
4632             }
4633         }
4634 
4635         /**
4636          * Reads alpha color component from temporal buffer using float64 data
4637          * type.
4638          */
4639         private class AlphaFloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4640 
4641             /**
4642              * Reads alpha color component from temporal buffer and sets its
4643              * value on current loader iterator.
4644              *
4645              * @param buffer Temporal buffer.
4646              */
4647             @Override
4648             public void readValueFromBuffer(final ByteBuffer buffer) {
4649                 final var value = buffer.getDouble(0);
4650 
4651                 loaderIterator.alpha = (short) value;
4652             }
4653         }
4654 
4655         /**
4656          * Reads red color component from temporal buffer using char data type.
4657          */
4658         private class RedCharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4659 
4660             /**
4661              * Reads red color component from temporal buffer and sets its value
4662              * on current loader iterator.
4663              *
4664              * @param buffer Temporal buffer.
4665              */
4666             @Override
4667             public void readValueFromBuffer(final ByteBuffer buffer) {
4668                 loaderIterator.red = buffer.get(0);
4669             }
4670         }
4671 
4672         /**
4673          * Reads green color component from temporal buffer using char data
4674          * type.
4675          */
4676         private class GreenCharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4677 
4678             /**
4679              * Reads green color component from temporal buffer and sets its
4680              * value on current loader iterator.
4681              *
4682              * @param buffer Temporal buffer.
4683              */
4684             @Override
4685             public void readValueFromBuffer(final ByteBuffer buffer) {
4686                 loaderIterator.green = buffer.get(0);
4687             }
4688         }
4689 
4690         /**
4691          * Reads blue color component from temporal buffer using char data type.
4692          */
4693         private class BlueCharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4694 
4695             /**
4696              * Reads blue color component from temporal buffer and sets its
4697              * value on current loader iterator.
4698              *
4699              * @param buffer Temporal buffer.
4700              */
4701             @Override
4702             public void readValueFromBuffer(final ByteBuffer buffer) {
4703                 loaderIterator.blue = buffer.get(0);
4704             }
4705         }
4706 
4707         /**
4708          * Reads alpha color component from temporal buffer using char data
4709          * type.
4710          */
4711         private class AlphaCharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4712 
4713             /**
4714              * Reads alpha color component from temporal buffer and sets its
4715              * value on current loader iterator.
4716              *
4717              * @param buffer Temporal buffer.
4718              */
4719             @Override
4720             public void readValueFromBuffer(final ByteBuffer buffer) {
4721                 loaderIterator.alpha = buffer.get(0);
4722             }
4723         }
4724 
4725         /**
4726          * Reads red color component from temporal buffer using uchar data type.
4727          */
4728         private class RedUcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4729 
4730             /**
4731              * Reads red color component from temporal buffer and sets its value
4732              * on current loader iterator.
4733              *
4734              * @param buffer Temporal buffer.
4735              */
4736             @Override
4737             public void readValueFromBuffer(final ByteBuffer buffer) {
4738                 // because java doesn't support unsigned types we use the next
4739                 // type that can hold all desired values
4740                 loaderIterator.red = buffer.getShort(0);
4741             }
4742         }
4743 
4744         /**
4745          * Reads green color component from temporal buffer using uchar data
4746          * type.
4747          */
4748         private class GreenUcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4749 
4750             /**
4751              * Reads green color component from temporal buffer and sets its
4752              * value on current loader iterator.
4753              *
4754              * @param buffer Temporal buffer.
4755              */
4756             @Override
4757             public void readValueFromBuffer(final ByteBuffer buffer) {
4758                 // because java doesn't support unsigned types we use the next
4759                 // type that can hold all desired values
4760                 loaderIterator.green = buffer.getShort(0);
4761             }
4762         }
4763 
4764         /**
4765          * Reads blue color component from temporal buffer using uchar data
4766          * type.
4767          */
4768         private class BlueUcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4769 
4770             /**
4771              * Reads blue color component from temporal buffer and sets its
4772              * value on current loader iterator.
4773              *
4774              * @param buffer Temporal buffer.
4775              */
4776             @Override
4777             public void readValueFromBuffer(final ByteBuffer buffer) {
4778                 // because java doesn't support unsigned types we use the next
4779                 // type that can hold all desired values
4780                 loaderIterator.blue = buffer.getShort(0);
4781             }
4782         }
4783 
4784         /**
4785          * Reads alpha color component from temporal buffer using uchar data
4786          * type.
4787          */
4788         private class AlphaUcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4789 
4790             /**
4791              * Reads alpha color component from temporal buffer and sets its
4792              * value on current loader iterator.
4793              *
4794              * @param buffer Temporal buffer.
4795              */
4796             @Override
4797             public void readValueFromBuffer(final ByteBuffer buffer) {
4798                 // because java doesn't support unsigned types we use the next
4799                 // type that can hold all desired values
4800                 loaderIterator.alpha = buffer.getShort(0);
4801             }
4802         }
4803 
4804         /**
4805          * Reads red color component from temporal buffer using short data type.
4806          */
4807         private class RedShortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4808 
4809             /**
4810              * Reads red color component from temporal buffer and sets its value
4811              * on current loader iterator.
4812              *
4813              * @param buffer Temporal buffer.
4814              */
4815             @Override
4816             public void readValueFromBuffer(final ByteBuffer buffer) {
4817                 loaderIterator.red = buffer.getShort(0);
4818             }
4819         }
4820 
4821         /**
4822          * Reads green color component from temporal buffer using short data
4823          * type.
4824          */
4825         private class GreenShortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4826 
4827             /**
4828              * Reads green color component from temporal buffer and sets its
4829              * value on current loader iterator.
4830              *
4831              * @param buffer Temporal buffer.
4832              */
4833             @Override
4834             public void readValueFromBuffer(final ByteBuffer buffer) {
4835                 loaderIterator.green = buffer.getShort(0);
4836             }
4837         }
4838 
4839         /**
4840          * Reads blue color component from temporal buffer using short data
4841          * type.
4842          */
4843         private class BlueShortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4844 
4845             /**
4846              * Reads blue color component from temporal buffer and sets its
4847              * value on current loader iterator.
4848              *
4849              * @param buffer Temporal buffer.
4850              */
4851             @Override
4852             public void readValueFromBuffer(final ByteBuffer buffer) {
4853                 loaderIterator.blue = buffer.getShort(0);
4854             }
4855         }
4856 
4857         /**
4858          * Reads alpha color component from temporal buffer using short data
4859          * type.
4860          */
4861         private class AlphaShortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4862 
4863             /**
4864              * Reads alpha color component from temporal buffer and sets its
4865              * value on current loader iterator.
4866              *
4867              * @param buffer Temporal buffer.
4868              */
4869             @Override
4870             public void readValueFromBuffer(final ByteBuffer buffer) {
4871                 loaderIterator.alpha = buffer.getShort(0);
4872             }
4873         }
4874 
4875         /**
4876          * Reads red color component from temporal buffer using ushort data
4877          * type.
4878          */
4879         private class RedUshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4880 
4881             /**
4882              * Reads red color component from temporal buffer and sets its value
4883              * on current loader iterator.
4884              *
4885              * @param buffer Temporal buffer.
4886              */
4887             @Override
4888             public void readValueFromBuffer(final ByteBuffer buffer) {
4889                 // because java doesn't support unsigned types we use the next
4890                 // type that can hold all desired values
4891                 final var value = buffer.getInt(0);
4892 
4893                 loaderIterator.red = (short) value;
4894             }
4895         }
4896 
4897         /**
4898          * Reads green color component from temporal buffer using ushort data
4899          * type.
4900          */
4901         private class GreenUshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4902 
4903             /**
4904              * Reads green color component from temporal buffer and sets its
4905              * value on current loader iterator.
4906              *
4907              * @param buffer Temporal buffer.
4908              */
4909             @Override
4910             public void readValueFromBuffer(final ByteBuffer buffer) {
4911                 // because java doesn't support unsigned types we use the next
4912                 // type that can hold all desired values
4913                 final var value = buffer.getInt(0);
4914 
4915                 loaderIterator.green = (short) value;
4916             }
4917         }
4918 
4919         /**
4920          * Reads blue color component from temporal buffer using ushort data
4921          * type.
4922          */
4923         private class BlueUshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4924 
4925             /**
4926              * Reads blue color component from temporal buffer and sets its
4927              * value on current loader iterator.
4928              *
4929              * @param buffer Temporal buffer.
4930              */
4931             @Override
4932             public void readValueFromBuffer(final ByteBuffer buffer) {
4933                 // because java doesn't support unsigned types we use the next
4934                 // type that can hold all desired values
4935                 final var value = buffer.getInt(0);
4936 
4937                 loaderIterator.blue = (short) value;
4938             }
4939         }
4940 
4941         /**
4942          * Reads alpha color component from temporal buffer using ushort data
4943          * type.
4944          */
4945         private class AlphaUshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4946 
4947             /**
4948              * Reads alpha color component from temporal buffer and sets its
4949              * value on current loader iterator.
4950              *
4951              * @param buffer Temporal buffer.
4952              */
4953             @Override
4954             public void readValueFromBuffer(final ByteBuffer buffer) {
4955                 // because java doesn't support unsigned types we use the next
4956                 // type that can hold all desired values
4957                 final var value = buffer.getInt(0);
4958 
4959                 loaderIterator.alpha = (short) value;
4960             }
4961         }
4962 
4963         /**
4964          * Reads red color component from temporal buffer using int data type.
4965          */
4966         private class RedIntReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4967 
4968             /**
4969              * Reads red color component from temporal buffer and sets its value
4970              * on current loader iterator.
4971              *
4972              * @param buffer Temporal buffer.
4973              */
4974             @Override
4975             public void readValueFromBuffer(final ByteBuffer buffer) {
4976                 final var value = buffer.getInt(0);
4977 
4978                 loaderIterator.red = (short) value;
4979             }
4980         }
4981 
4982         /**
4983          * Reads green color component from temporal buffer using int data type.
4984          */
4985         private class GreenIntReadValueFromBufferListener implements PLYReadValueFromBufferListener {
4986 
4987             /**
4988              * Reads green color component from temporal buffer and sets its
4989              * value on current loader iterator.
4990              *
4991              * @param buffer Temporal buffer.
4992              */
4993             @Override
4994             public void readValueFromBuffer(final ByteBuffer buffer) {
4995                 final var value = buffer.getInt(0);
4996 
4997                 loaderIterator.green = (short) value;
4998             }
4999         }
5000 
5001         /**
5002          * Reads blue color component from temporal buffer using int data type.
5003          */
5004         private class BlueIntReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5005 
5006             /**
5007              * Reads blue color component from temporal buffer and sets its
5008              * value on current loader iterator.
5009              *
5010              * @param buffer Temporal buffer.
5011              */
5012             @Override
5013             public void readValueFromBuffer(final ByteBuffer buffer) {
5014                 final var value = buffer.getInt(0);
5015 
5016                 loaderIterator.blue = (short) value;
5017             }
5018         }
5019 
5020         /**
5021          * Reads alpha color component from temporal buffer using int data type.
5022          */
5023         private class AlphaIntReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5024 
5025             /**
5026              * Reads alpha color component from temporal buffer and sets its
5027              * value on current loader iterator.
5028              *
5029              * @param buffer Temporal buffer.
5030              */
5031             @Override
5032             public void readValueFromBuffer(final ByteBuffer buffer) {
5033                 final var value = buffer.getInt(0);
5034 
5035                 loaderIterator.alpha = (short) value;
5036             }
5037         }
5038 
5039         /**
5040          * Reads red color component from temporal buffer using uint data type.
5041          */
5042         private class RedUintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5043 
5044             /**
5045              * Reads red color component from temporal buffer and sets its value
5046              * on current loader iterator.
5047              *
5048              * @param buffer Temporal buffer.
5049              */
5050             @Override
5051             public void readValueFromBuffer(final ByteBuffer buffer) {
5052                 // because java doesn't support unsigned types we use the next
5053                 // type that can hold all desired values
5054                 final var value = buffer.getLong(0);
5055 
5056                 loaderIterator.red = (short) value;
5057             }
5058         }
5059 
5060         /**
5061          * Reads green color component from temporal buffer using uint data
5062          * type.
5063          */
5064         private class GreenUintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5065 
5066             /**
5067              * Reads green color component from temporal buffer and sets its
5068              * value on current loader iterator.
5069              *
5070              * @param buffer Temporal buffer.
5071              */
5072             @Override
5073             public void readValueFromBuffer(final ByteBuffer buffer) {
5074                 // because java doesn't support unsigned types we use the next
5075                 // type that can hold all desired values
5076                 final var value = buffer.getLong(0);
5077 
5078                 loaderIterator.green = (short) value;
5079             }
5080         }
5081 
5082         /**
5083          * Reads blue color component from temporal buffer using uint data type.
5084          */
5085         private class BlueUintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5086 
5087             /**
5088              * Reads blue color component from temporal buffer and sets its
5089              * value on current loader iterator.
5090              *
5091              * @param buffer Temporal buffer.
5092              */
5093             @Override
5094             public void readValueFromBuffer(final ByteBuffer buffer) {
5095                 // because java doesn't support unsigned types we use the next
5096                 // type that can hold all desired values
5097                 final var value = buffer.getLong(0);
5098 
5099                 loaderIterator.blue = (short) value;
5100             }
5101         }
5102 
5103         /**
5104          * Reads alpha color component from temporal buffer using uint data
5105          * type.
5106          */
5107         private class AlphaUintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5108 
5109             /**
5110              * Reads alpha color component from temporal buffer and sets its
5111              * value on current loader iterator.
5112              *
5113              * @param buffer Temporal buffer.
5114              */
5115             @Override
5116             public void readValueFromBuffer(final ByteBuffer buffer) {
5117                 // because java doesn't support unsigned types we use the next
5118                 // type that can hold all desired values
5119                 final var value = buffer.getLong(0);
5120 
5121                 loaderIterator.alpha = (short) value;
5122             }
5123         }
5124 
5125         /**
5126          * Reads red color component from temporal buffer using float data type.
5127          */
5128         private class RedFloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5129 
5130             /**
5131              * Reads red color component from temporal buffer and sets its value
5132              * on current loader iterator.
5133              *
5134              * @param buffer Temporal buffer.
5135              */
5136             @Override
5137             public void readValueFromBuffer(final ByteBuffer buffer) {
5138                 final var value = buffer.getFloat(0);
5139 
5140                 loaderIterator.red = (short) value;
5141             }
5142         }
5143 
5144         /**
5145          * Reads green color component from temporal buffer using float data
5146          * type.
5147          */
5148         private class GreenFloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5149 
5150             /**
5151              * Reads green color component from temporal buffer and sets its
5152              * value on current loader iterator.
5153              *
5154              * @param buffer Temporal buffer.
5155              */
5156             @Override
5157             public void readValueFromBuffer(final ByteBuffer buffer) {
5158                 final var value = buffer.getFloat(0);
5159 
5160                 loaderIterator.green = (short) value;
5161             }
5162         }
5163 
5164         /**
5165          * Reads blue color component from temporal buffer using float data
5166          * type.
5167          */
5168         private class BlueFloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5169 
5170             /**
5171              * Reads blue color component from temporal buffer and sets its
5172              * value on current loader iterator.
5173              *
5174              * @param buffer Temporal buffer.
5175              */
5176             @Override
5177             public void readValueFromBuffer(final ByteBuffer buffer) {
5178                 final var value = buffer.getFloat(0);
5179 
5180                 loaderIterator.blue = (short) value;
5181             }
5182         }
5183 
5184         /**
5185          * Reads alpha color component from temporal buffer using float data
5186          * type.
5187          */
5188         private class AlphaFloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5189 
5190             /**
5191              * Reads alpha color component from temporal buffer and sets its
5192              * value on current loader iterator.
5193              *
5194              * @param buffer Temporal buffer.
5195              */
5196             @Override
5197             public void readValueFromBuffer(final ByteBuffer buffer) {
5198                 final var value = buffer.getFloat(0);
5199 
5200                 loaderIterator.alpha = (short) value;
5201             }
5202         }
5203 
5204         /**
5205          * Reads red color component from temporal buffer using double data
5206          * type.
5207          */
5208         private class RedDoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5209 
5210             /**
5211              * Reads red color component from temporal buffer and sets its value
5212              * on current loader iterator.
5213              *
5214              * @param buffer Temporal buffer.
5215              */
5216             @Override
5217             public void readValueFromBuffer(final ByteBuffer buffer) {
5218                 final var value = buffer.getDouble(0);
5219 
5220                 loaderIterator.red = (short) value;
5221             }
5222         }
5223 
5224         /**
5225          * Reads green color component from temporal buffer using double data
5226          * type.
5227          */
5228         private class GreenDoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5229 
5230             /**
5231              * Reads green color component from temporal buffer and sets its
5232              * value on current loader iterator.
5233              *
5234              * @param buffer Temporal buffer.
5235              */
5236             @Override
5237             public void readValueFromBuffer(final ByteBuffer buffer) {
5238                 final var value = buffer.getDouble(0);
5239 
5240                 loaderIterator.green = (short) value;
5241             }
5242         }
5243 
5244         /**
5245          * Reads blue color component from temporal buffer using double data
5246          * type.
5247          */
5248         private class BlueDoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5249 
5250             /**
5251              * Reads blue color component from temporal buffer and sets its
5252              * value on current loader iterator.
5253              *
5254              * @param buffer Temporal buffer.
5255              */
5256             @Override
5257             public void readValueFromBuffer(final ByteBuffer buffer) {
5258                 final var value = buffer.getDouble(0);
5259 
5260                 loaderIterator.blue = (short) value;
5261             }
5262         }
5263 
5264         /**
5265          * Reads alpha color component from temporal buffer using double data
5266          * type.
5267          */
5268         private class AlphaDoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5269 
5270             /**
5271              * Reads alpha color component from temporal buffer and sets its
5272              * value on current loader iterator.
5273              *
5274              * @param buffer Temporal buffer.
5275              */
5276             @Override
5277             public void readValueFromBuffer(final ByteBuffer buffer) {
5278                 final var value = buffer.getDouble(0);
5279 
5280                 loaderIterator.alpha = (short) value;
5281             }
5282         }
5283 
5284         /**
5285          * Reads a vertex normal x coordinate component from temporal buffer
5286          * using int8 type.
5287          */
5288         private class NXint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5289 
5290             /**
5291              * Reads a vertex normal x coordinate from temporal buffer and sets
5292              * its value on current loader iterator.
5293              *
5294              * @param buffer Temporal buffer.
5295              */
5296             @Override
5297             public void readValueFromBuffer(final ByteBuffer buffer) {
5298                 loaderIterator.nX = buffer.get(0);
5299             }
5300         }
5301 
5302         /**
5303          * Reads a vertex normal y coordinate component from temporal buffer
5304          * using int8 type.
5305          */
5306         private class NYint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5307 
5308             /**
5309              * Reads a vertex normal y coordinate from temporal buffer and sets
5310              * its value on current loader iterator.
5311              *
5312              * @param buffer Temporal buffer.
5313              */
5314             @Override
5315             public void readValueFromBuffer(final ByteBuffer buffer) {
5316                 loaderIterator.nY = buffer.get(0);
5317             }
5318         }
5319 
5320         /**
5321          * Reads a vertex normal z coordinate component from temporal buffer
5322          * using int8 type.
5323          */
5324         private class NZint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5325 
5326             /**
5327              * Reads a vertex normal z coordinate from temporal buffer and sets
5328              * its value on current loader iterator.
5329              *
5330              * @param buffer Temporal buffer.
5331              */
5332             @Override
5333             public void readValueFromBuffer(final ByteBuffer buffer) {
5334                 loaderIterator.nZ = buffer.get(0);
5335             }
5336         }
5337 
5338         /**
5339          * Reads a vertex normal x coordinate component from temporal buffer
5340          * using uint8 type.
5341          */
5342         private class NXuint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5343 
5344             /**
5345              * Reads a vertex normal x coordinate from temporal buffer and sets
5346              * its value on current loader iterator.
5347              *
5348              * @param buffer Temporal buffer.
5349              */
5350             @Override
5351             public void readValueFromBuffer(final ByteBuffer buffer) {
5352                 // because java doesn't support unsigned types we use the next
5353                 // type that can hold all desired values
5354                 loaderIterator.nX = buffer.getShort(0);
5355             }
5356         }
5357 
5358         /**
5359          * Reads a vertex normal y coordinate component from temporal buffer
5360          * using uint8 type.
5361          */
5362         private class NYuint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5363 
5364             /**
5365              * Reads a vertex normal y coordinate from temporal buffer and sets
5366              * its value on current loader iterator.
5367              *
5368              * @param buffer Temporal buffer.
5369              */
5370             @Override
5371             public void readValueFromBuffer(final ByteBuffer buffer) {
5372                 // because java doesn't support unsigned types we use the next
5373                 // type that can hold all desired values
5374                 loaderIterator.nY = buffer.getShort(0);
5375             }
5376         }
5377 
5378         /**
5379          * Reads a vertex normal z coordinate component from temporal buffer
5380          * using uint8 type.
5381          */
5382         private class NZuint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5383 
5384             /**
5385              * Reads a vertex normal z coordinate from temporal buffer and sets
5386              * its value on current loader iterator.
5387              *
5388              * @param buffer Temporal buffer.
5389              */
5390             @Override
5391             public void readValueFromBuffer(final ByteBuffer buffer) {
5392                 // because java doesn't support unsigned types we use the next
5393                 // type that can hold all desired values
5394                 loaderIterator.nZ = buffer.getShort(0);
5395             }
5396         }
5397 
5398         /**
5399          * Reads a vertex normal x coordinate component from temporal buffer
5400          * using int16 type.
5401          */
5402         private class NXint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5403 
5404             /**
5405              * Reads a vertex normal x coordinate from temporal buffer and sets
5406              * its value on current loader iterator.
5407              *
5408              * @param buffer Temporal buffer.
5409              */
5410             @Override
5411             public void readValueFromBuffer(final ByteBuffer buffer) {
5412                 loaderIterator.nX = buffer.getShort(0);
5413             }
5414         }
5415 
5416         /**
5417          * Reads a vertex normal y coordinate component from temporal buffer
5418          * using int16 type.
5419          */
5420         private class NYint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5421 
5422             /**
5423              * Reads a vertex normal y coordinate from temporal buffer and sets
5424              * its value on current loader iterator.
5425              *
5426              * @param buffer Temporal buffer.
5427              */
5428             @Override
5429             public void readValueFromBuffer(final ByteBuffer buffer) {
5430                 loaderIterator.nY = buffer.getShort(0);
5431             }
5432         }
5433 
5434         /**
5435          * Reads a vertex normal z coordinate component from temporal buffer
5436          * using int16 type.
5437          */
5438         private class NZint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5439 
5440             /**
5441              * Reads a vertex normal z coordinate from temporal buffer and sets
5442              * its value on current loader iterator.
5443              *
5444              * @param buffer Temporal buffer.
5445              */
5446             @Override
5447             public void readValueFromBuffer(final ByteBuffer buffer) {
5448                 loaderIterator.nZ = buffer.getShort(0);
5449             }
5450         }
5451 
5452         /**
5453          * Reads a vertex normal x coordinate component from temporal buffer
5454          * using uint16 type.
5455          */
5456         private class NXuint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5457 
5458             /**
5459              * Reads a vertex normal x coordinate from temporal buffer and sets
5460              * its value on current loader iterator.
5461              *
5462              * @param buffer Temporal buffer.
5463              */
5464             @Override
5465             public void readValueFromBuffer(final ByteBuffer buffer) {
5466                 // because java doesn't support unsigned types we use the next
5467                 // type that can hold all desired values
5468                 loaderIterator.nX = buffer.getInt(0);
5469             }
5470         }
5471 
5472         /**
5473          * Reads a vertex normal y coordinate component from temporal buffer
5474          * using uint16 type.
5475          */
5476         private class NYuint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5477 
5478             /**
5479              * Reads a vertex normal y coordinate from temporal buffer and sets
5480              * its value on current loader iterator.
5481              *
5482              * @param buffer Temporal buffer.
5483              */
5484             @Override
5485             public void readValueFromBuffer(final ByteBuffer buffer) {
5486                 // because java doesn't support unsigned types we use the next
5487                 // type that can hold all desired values
5488                 loaderIterator.nY = buffer.getInt(0);
5489             }
5490         }
5491 
5492         /**
5493          * Reads a vertex normal z coordinate component from temporal buffer
5494          * using uint16 type.
5495          */
5496         private class NZuint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5497 
5498             /**
5499              * Reads a vertex normal z coordinate from temporal buffer and sets
5500              * its value on current loader iterator.
5501              *
5502              * @param buffer Temporal buffer.
5503              */
5504             @Override
5505             public void readValueFromBuffer(final ByteBuffer buffer) {
5506                 // because java doesn't support unsigned types we use the next
5507                 // type that can hold all desired values
5508                 loaderIterator.nZ = buffer.getInt(0);
5509             }
5510         }
5511 
5512         /**
5513          * Reads a vertex normal x coordinate component from temporal buffer
5514          * using int32 type.
5515          */
5516         private class NXint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5517 
5518             /**
5519              * Reads a vertex normal x coordinate from temporal buffer and sets
5520              * its value on current loader iterator.
5521              *
5522              * @param buffer Temporal buffer.
5523              */
5524             @Override
5525             public void readValueFromBuffer(final ByteBuffer buffer) {
5526                 loaderIterator.nX = buffer.getInt(0);
5527             }
5528         }
5529 
5530         /**
5531          * Reads a vertex normal y coordinate component from temporal buffer
5532          * using int32 type.
5533          */
5534         private class NYint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5535 
5536             /**
5537              * Reads a vertex normal y coordinate from temporal buffer and sets
5538              * its value on current loader iterator.
5539              *
5540              * @param buffer Temporal buffer.
5541              */
5542             @Override
5543             public void readValueFromBuffer(final ByteBuffer buffer) {
5544                 loaderIterator.nY = buffer.getInt(0);
5545             }
5546         }
5547 
5548         /**
5549          * Reads a vertex normal z coordinate component from temporal buffer
5550          * using int32 type.
5551          */
5552         private class NZint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5553 
5554             /**
5555              * Reads a vertex normal z coordinate from temporal buffer and sets
5556              * its value on current loader iterator.
5557              *
5558              * @param buffer Temporal buffer.
5559              */
5560             @Override
5561             public void readValueFromBuffer(final ByteBuffer buffer) {
5562                 loaderIterator.nZ = buffer.getInt(0);
5563             }
5564         }
5565 
5566         /**
5567          * Reads a vertex normal x coordinate component from temporal buffer
5568          * using int32 type.
5569          */
5570         private class NXuint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5571 
5572             /**
5573              * Reads a vertex normal x coordinate from temporal buffer and sets
5574              * its value on current loader iterator.
5575              *
5576              * @param buffer Temporal buffer.
5577              */
5578             @Override
5579             public void readValueFromBuffer(final ByteBuffer buffer) {
5580                 // because java doesn't support unsigned types we use the next
5581                 // type that can hold all desired values
5582                 loaderIterator.nX = buffer.getLong(0);
5583             }
5584         }
5585 
5586         /**
5587          * Reads a vertex normal y coordinate component from temporal buffer
5588          * using uint32 type.
5589          */
5590         private class NYuint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5591 
5592             /**
5593              * Reads a vertex normal y coordinate from temporal buffer and sets
5594              * its value on current loader iterator.
5595              *
5596              * @param buffer Temporal buffer.
5597              */
5598             @Override
5599             public void readValueFromBuffer(final ByteBuffer buffer) {
5600                 // because java doesn't support unsigned types we use the next
5601                 // type that can hold all desired values
5602                 loaderIterator.nY = buffer.getLong(0);
5603             }
5604         }
5605 
5606         /**
5607          * Reads a vertex normal z coordinate component from temporal buffer
5608          * using uint32 type.
5609          */
5610         private class NZuint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5611 
5612             /**
5613              * Reads a vertex normal z coordinate from temporal buffer and sets
5614              * its value on current loader iterator.
5615              *
5616              * @param buffer Temporal buffer.
5617              */
5618             @Override
5619             public void readValueFromBuffer(final ByteBuffer buffer) {
5620                 // because java doesn't support unsigned types we use the next
5621                 // type that can hold all desired values
5622                 loaderIterator.nZ = buffer.getLong(0);
5623             }
5624         }
5625 
5626         /**
5627          * Reads a vertex normal x coordinate component from temporal buffer
5628          * using float32 type.
5629          */
5630         private class NXfloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5631 
5632             /**
5633              * Reads a vertex normal x coordinate from temporal buffer and sets
5634              * its value on current loader iterator.
5635              *
5636              * @param buffer Temporal buffer.
5637              */
5638             @Override
5639             public void readValueFromBuffer(final ByteBuffer buffer) {
5640                 loaderIterator.nX = buffer.getFloat(0);
5641             }
5642         }
5643 
5644         /**
5645          * Reads a vertex normal y coordinate component from temporal buffer
5646          * using float32 type.
5647          */
5648         private class NYfloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5649 
5650             /**
5651              * Reads a vertex normal y coordinate from temporal buffer and sets
5652              * its value on current loader iterator.
5653              *
5654              * @param buffer Temporal buffer.
5655              */
5656             @Override
5657             public void readValueFromBuffer(final ByteBuffer buffer) {
5658                 loaderIterator.nY = buffer.getFloat(0);
5659             }
5660         }
5661 
5662         /**
5663          * Reads a vertex normal z coordinate component from temporal buffer
5664          * using float32 type.
5665          */
5666         private class NZfloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5667 
5668             /**
5669              * Reads a vertex normal z coordinate from temporal buffer and sets
5670              * its value on current loader iterator.
5671              *
5672              * @param buffer Temporal buffer.
5673              */
5674             @Override
5675             public void readValueFromBuffer(final ByteBuffer buffer) {
5676                 loaderIterator.nZ = buffer.getFloat(0);
5677             }
5678         }
5679 
5680         /**
5681          * Reads a vertex normal x coordinate component from temporal buffer
5682          * using float64 type.
5683          */
5684         private class NXfloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5685 
5686             /**
5687              * Reads a vertex normal x coordinate from temporal buffer and sets
5688              * its value on current loader iterator.
5689              *
5690              * @param buffer Temporal buffer.
5691              */
5692             @Override
5693             public void readValueFromBuffer(final ByteBuffer buffer) {
5694                 final var value = buffer.getDouble(0);
5695 
5696                 loaderIterator.nX = (float) value;
5697             }
5698         }
5699 
5700         /**
5701          * Reads a vertex normal y coordinate component from temporal buffer
5702          * using float64 type.
5703          */
5704         private class NYfloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5705 
5706             /**
5707              * Reads a vertex normal y coordinate from temporal buffer and sets
5708              * its value on current loader iterator.
5709              *
5710              * @param buffer Temporal buffer.
5711              */
5712             @Override
5713             public void readValueFromBuffer(final ByteBuffer buffer) {
5714                 final var value = buffer.getDouble(0);
5715 
5716                 loaderIterator.nY = (float) value;
5717             }
5718         }
5719 
5720         /**
5721          * Reads a vertex normal z coordinate component from temporal buffer
5722          * using float64 type.
5723          */
5724         private class NZfloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5725 
5726             /**
5727              * Reads a vertex normal z coordinate from temporal buffer and sets
5728              * its value on current loader iterator.
5729              *
5730              * @param buffer Temporal buffer.
5731              */
5732             @Override
5733             public void readValueFromBuffer(final ByteBuffer buffer) {
5734                 final var value = buffer.getDouble(0);
5735 
5736                 loaderIterator.nZ = (float) value;
5737             }
5738         }
5739 
5740         /**
5741          * Reads a vertex normal x coordinate component from temporal buffer
5742          * using char type.
5743          */
5744         private class NXcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5745 
5746             /**
5747              * Reads a vertex normal x coordinate from temporal buffer and sets
5748              * its value on current loader iterator.
5749              *
5750              * @param buffer Temporal buffer.
5751              */
5752             @Override
5753             public void readValueFromBuffer(final ByteBuffer buffer) {
5754                 loaderIterator.nX = buffer.get(0);
5755             }
5756         }
5757 
5758         /**
5759          * Reads a vertex normal y coordinate component from temporal buffer
5760          * using char type.
5761          */
5762         private class NYcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5763 
5764             /**
5765              * Reads a vertex normal y coordinate from temporal buffer and sets
5766              * its value on current loader iterator.
5767              *
5768              * @param buffer Temporal buffer.
5769              */
5770             @Override
5771             public void readValueFromBuffer(final ByteBuffer buffer) {
5772                 loaderIterator.nY = buffer.get(0);
5773             }
5774         }
5775 
5776         /**
5777          * Reads a vertex normal z coordinate component from temporal buffer
5778          * using char type.
5779          */
5780         private class NZcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5781 
5782             /**
5783              * Reads a vertex normal z coordinate from temporal buffer and sets
5784              * its value on current loader iterator.
5785              *
5786              * @param buffer Temporal buffer.
5787              */
5788             @Override
5789             public void readValueFromBuffer(final ByteBuffer buffer) {
5790                 loaderIterator.nZ = buffer.get(0);
5791             }
5792         }
5793 
5794         /**
5795          * Reads a vertex normal x coordinate component from temporal buffer
5796          * using uchar type.
5797          */
5798         private class NXucharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5799 
5800             /**
5801              * Reads a vertex normal x coordinate from temporal buffer and sets
5802              * its value on current loader iterator.
5803              *
5804              * @param buffer Temporal buffer.
5805              */
5806             @Override
5807             public void readValueFromBuffer(final ByteBuffer buffer) {
5808                 // because java doesn't support unsigned types we use the next
5809                 // type that can hold all desired values
5810                 loaderIterator.nX = buffer.getShort(0);
5811             }
5812         }
5813 
5814         /**
5815          * Reads a vertex normal y coordinate component from temporal buffer
5816          * using uchar type.
5817          */
5818         private class NYucharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5819 
5820             /**
5821              * Reads a vertex normal y coordinate from temporal buffer and sets
5822              * its value on current loader iterator.
5823              *
5824              * @param buffer Temporal buffer.
5825              */
5826             @Override
5827             public void readValueFromBuffer(final ByteBuffer buffer) {
5828                 // because java doesn't support unsigned types we use the next
5829                 // type that can hold all desired values
5830                 loaderIterator.nY = buffer.getShort(0);
5831             }
5832         }
5833 
5834         /**
5835          * Reads a vertex normal z coordinate component from temporal buffer
5836          * using uchar type.
5837          */
5838         private class NZucharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5839 
5840             /**
5841              * Reads a vertex normal z coordinate from temporal buffer and sets
5842              * its value on current loader iterator.
5843              *
5844              * @param buffer Temporal buffer.
5845              */
5846             @Override
5847             public void readValueFromBuffer(final ByteBuffer buffer) {
5848                 // because java doesn't support unsigned types we use the next
5849                 // type that can hold all desired values
5850                 loaderIterator.nZ = buffer.getShort(0);
5851             }
5852         }
5853 
5854         /**
5855          * Reads a vertex normal x coordinate component from temporal buffer
5856          * using short type.
5857          */
5858         private class NXshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5859 
5860             /**
5861              * Reads a vertex normal x coordinate from temporal buffer and sets
5862              * its value on current loader iterator.
5863              *
5864              * @param buffer Temporal buffer.
5865              */
5866             @Override
5867             public void readValueFromBuffer(final ByteBuffer buffer) {
5868                 loaderIterator.nX = buffer.getShort(0);
5869             }
5870         }
5871 
5872         /**
5873          * Reads a vertex normal y coordinate component from temporal buffer
5874          * using short type.
5875          */
5876         private class NYshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5877 
5878             /**
5879              * Reads a vertex normal y coordinate from temporal buffer and sets
5880              * its value on current loader iterator.
5881              *
5882              * @param buffer Temporal buffer.
5883              */
5884             @Override
5885             public void readValueFromBuffer(final ByteBuffer buffer) {
5886                 loaderIterator.nY = buffer.getShort(0);
5887             }
5888         }
5889 
5890         /**
5891          * Reads a vertex normal z coordinate component from temporal buffer
5892          * using short type.
5893          */
5894         private class NZshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5895 
5896             /**
5897              * Reads a vertex normal z coordinate from temporal buffer and sets
5898              * its value on current loader iterator.
5899              *
5900              * @param buffer Temporal buffer.
5901              */
5902             @Override
5903             public void readValueFromBuffer(final ByteBuffer buffer) {
5904                 loaderIterator.nZ = buffer.getShort(0);
5905             }
5906         }
5907 
5908         /**
5909          * Reads a vertex normal x coordinate component from temporal buffer
5910          * using ushort type.
5911          */
5912         private class NXushortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5913 
5914             /**
5915              * Reads a vertex normal x coordinate from temporal buffer and sets
5916              * its value on current loader iterator.
5917              *
5918              * @param buffer Temporal buffer.
5919              */
5920             @Override
5921             public void readValueFromBuffer(final ByteBuffer buffer) {
5922                 // because java doesn't support unsigned types we use the next
5923                 // type that can hold all desired values
5924                 loaderIterator.nX = buffer.getInt(0);
5925             }
5926         }
5927 
5928         /**
5929          * Reads a vertex normal y coordinate component from temporal buffer
5930          * using ushort type.
5931          */
5932         private class NYushortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5933 
5934             /**
5935              * Reads a vertex normal y coordinate from temporal buffer and sets
5936              * its value on current loader iterator.
5937              *
5938              * @param buffer Temporal buffer.
5939              */
5940             @Override
5941             public void readValueFromBuffer(final ByteBuffer buffer) {
5942                 // because java doesn't support unsigned types we use the next
5943                 // type that can hold all desired values
5944                 loaderIterator.nY = buffer.getInt(0);
5945             }
5946         }
5947 
5948         /**
5949          * Reads a vertex normal z coordinate component from temporal buffer
5950          * using ushort type.
5951          */
5952         private class NZushortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5953 
5954             /**
5955              * Reads a vertex normal z coordinate from temporal buffer and sets
5956              * its value on current loader iterator.
5957              *
5958              * @param buffer Temporal buffer.
5959              */
5960             @Override
5961             public void readValueFromBuffer(final ByteBuffer buffer) {
5962                 // because java doesn't support unsigned types we use the next
5963                 // type that can hold all desired values
5964                 loaderIterator.nZ = buffer.getInt(0);
5965             }
5966         }
5967 
5968         /**
5969          * Reads a vertex normal x coordinate component from temporal buffer
5970          * using int type.
5971          */
5972         private class NXintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5973 
5974             /**
5975              * Reads a vertex normal x coordinate from temporal buffer and sets
5976              * its value on current loader iterator.
5977              *
5978              * @param buffer Temporal buffer.
5979              */
5980             @Override
5981             public void readValueFromBuffer(final ByteBuffer buffer) {
5982                 loaderIterator.nX = buffer.getInt(0);
5983             }
5984         }
5985 
5986         /**
5987          * Reads a vertex normal y coordinate component from temporal buffer
5988          * using int type.
5989          */
5990         private class NYintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
5991 
5992             /**
5993              * Reads a vertex normal y coordinate from temporal buffer and sets
5994              * its value on current loader iterator.
5995              *
5996              * @param buffer Temporal buffer.
5997              */
5998             @Override
5999             public void readValueFromBuffer(final ByteBuffer buffer) {
6000                 loaderIterator.nY = buffer.getInt(0);
6001             }
6002         }
6003 
6004         /**
6005          * Reads a vertex normal z coordinate component from temporal buffer
6006          * using int type.
6007          */
6008         private class NZintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6009 
6010             /**
6011              * Reads a vertex normal z coordinate from temporal buffer and sets
6012              * its value on current loader iterator.
6013              *
6014              * @param buffer Temporal buffer.
6015              */
6016             @Override
6017             public void readValueFromBuffer(final ByteBuffer buffer) {
6018                 loaderIterator.nZ = buffer.getInt(0);
6019             }
6020         }
6021 
6022         /**
6023          * Reads a vertex normal x coordinate component from temporal buffer
6024          * using uint type.
6025          */
6026         private class NXuintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6027 
6028             /**
6029              * Reads a vertex normal x coordinate from temporal buffer and sets
6030              * its value on current loader iterator.
6031              *
6032              * @param buffer Temporal buffer.
6033              */
6034             @Override
6035             public void readValueFromBuffer(final ByteBuffer buffer) {
6036                 // because java doesn't support unsigned types we use the next
6037                 // type that can hold all desired values
6038                 loaderIterator.nX = buffer.getLong(0);
6039             }
6040         }
6041 
6042         /**
6043          * Reads a vertex normal y coordinate component from temporal buffer
6044          * using uint type.
6045          */
6046         private class NYuintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6047 
6048             /**
6049              * Reads a vertex normal y coordinate from temporal buffer and sets
6050              * its value on current loader iterator.
6051              *
6052              * @param buffer Temporal buffer.
6053              */
6054             @Override
6055             public void readValueFromBuffer(final ByteBuffer buffer) {
6056                 // because java doesn't support unsigned types we use the next
6057                 // type that can hold all desired values
6058                 loaderIterator.nY = buffer.getLong(0);
6059             }
6060         }
6061 
6062         /**
6063          * Reads a vertex normal z coordinate component from temporal buffer
6064          * using uint type.
6065          */
6066         private class NZuintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6067 
6068             /**
6069              * Reads a vertex normal z coordinate from temporal buffer and sets
6070              * its value on current loader iterator.
6071              *
6072              * @param buffer Temporal buffer.
6073              */
6074             @Override
6075             public void readValueFromBuffer(final ByteBuffer buffer) {
6076                 // because java doesn't support unsigned types we use the next
6077                 // type that can hold all desired values
6078                 loaderIterator.nZ = buffer.getLong(0);
6079             }
6080         }
6081 
6082         /**
6083          * Reads a vertex normal x coordinate component form temporal buffer
6084          * using float type.
6085          */
6086         private class NXfloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6087 
6088             /**
6089              * Reads a vertex normal x coordinate from temporal buffer and sets
6090              * its value on current loader iterator.
6091              *
6092              * @param buffer Temporal buffer.
6093              */
6094             @Override
6095             public void readValueFromBuffer(final ByteBuffer buffer) {
6096                 loaderIterator.nX = buffer.getFloat(0);
6097             }
6098         }
6099 
6100         /**
6101          * Reads a vertex normal y coordinate component from temporal buffer
6102          * using float type.
6103          */
6104         private class NYfloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6105 
6106             /**
6107              * Reads a vertex normal y coordinate from temporal buffer and sets
6108              * its value on current loader iterator.
6109              *
6110              * @param buffer Temporal buffer.
6111              */
6112             @Override
6113             public void readValueFromBuffer(final ByteBuffer buffer) {
6114                 loaderIterator.nY = buffer.getFloat(0);
6115             }
6116         }
6117 
6118         /**
6119          * Reads a vertex normal z coordinate component from temporal buffer
6120          * using float type.
6121          */
6122         private class NZfloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6123 
6124             /**
6125              * Reads a vertex normal z coordinate from temporal buffer and sets
6126              * its value on current loader iterator.
6127              *
6128              * @param buffer Temporal buffer.
6129              */
6130             @Override
6131             public void readValueFromBuffer(final ByteBuffer buffer) {
6132                 loaderIterator.nZ = buffer.getFloat(0);
6133             }
6134         }
6135 
6136         /**
6137          * Reads a vertex normal x coordinate component from temporal buffer
6138          * using double type.
6139          */
6140         private class NXdoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6141 
6142             /**
6143              * Reads a vertex normal x coordinate from temporal buffer and sets
6144              * its value on current loader iterator.
6145              *
6146              * @param buffer Temporal buffer.
6147              */
6148             @Override
6149             public void readValueFromBuffer(final ByteBuffer buffer) {
6150                 final var value = buffer.getDouble(0);
6151 
6152                 loaderIterator.nX = (float) value;
6153             }
6154         }
6155 
6156         /**
6157          * Reads a vertex normal y coordinate component from temporal buffer
6158          * using double type.
6159          */
6160         private class NYdoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6161 
6162             /**
6163              * Reads a vertex normal y coordinate from temporal buffer and sets
6164              * its value on current loader iterator.
6165              *
6166              * @param buffer Temporal buffer.
6167              */
6168             @Override
6169             public void readValueFromBuffer(final ByteBuffer buffer) {
6170                 final var value = buffer.getDouble(0);
6171 
6172                 loaderIterator.nY = (float) value;
6173             }
6174         }
6175 
6176         /**
6177          * Reads a vertex normal z coordinate component from temporal buffer
6178          * using double type.
6179          */
6180         private class NZdoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6181 
6182             /**
6183              * Reads a vertex normal z coordinate from temporal buffer and sets
6184              * its value on current loader iterator.
6185              *
6186              * @param buffer Temporal buffer.
6187              */
6188             @Override
6189             public void readValueFromBuffer(final ByteBuffer buffer) {
6190                 final var value = buffer.getDouble(0);
6191 
6192                 loaderIterator.nZ = (float) value;
6193             }
6194         }
6195 
6196         /**
6197          * Reads the index of a face/polygon vertex from temporal buffer using
6198          * int8 type.
6199          */
6200         private class FaceInt8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6201 
6202             /**
6203              * Reads the index of a face/polygon vertex from temporal buffer and
6204              * sets its value on current loader iterator.
6205              *
6206              * @param buffer Temporal buffer.
6207              */
6208             @Override
6209             public void readValueFromBuffer(final ByteBuffer buffer) {
6210                 loaderIterator.index = buffer.get(0);
6211             }
6212         }
6213 
6214         /**
6215          * Reads the index of a face/polygon vertex from temporal buffer using
6216          * uint8 type.
6217          */
6218         private class FaceUint8ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6219 
6220             /**
6221              * Reads the index of a face/polygon vertex from temporal buffer and
6222              * sets its value on current loader iterator.
6223              *
6224              * @param buffer Temporal buffer.
6225              */
6226             @Override
6227             public void readValueFromBuffer(final ByteBuffer buffer) {
6228                 // because java doesn't support unsigned types we use the next
6229                 // type that can hold all desired values
6230                 loaderIterator.index = buffer.getShort(0);
6231             }
6232         }
6233 
6234         /**
6235          * Reads the index of a face/polygon vertex from temporal buffer using
6236          * int16 type.
6237          */
6238         private class FaceInt16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6239 
6240             /**
6241              * Reads the index of a face/polygon vertex from temporal buffer and
6242              * sets its value on current loader iterator.
6243              *
6244              * @param buffer Temporal buffer.
6245              */
6246             @Override
6247             public void readValueFromBuffer(final ByteBuffer buffer) {
6248                 loaderIterator.index = buffer.getShort(0);
6249             }
6250         }
6251 
6252         /**
6253          * Reads the index of a face/polygon vertex from temporal buffer using
6254          * uint16 type.
6255          */
6256         private class FaceUint16ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6257 
6258             /**
6259              * Reads the index of a face/polygon vertex from temporal buffer and
6260              * sets its value on current loader iterator.
6261              *
6262              * @param buffer Temporal buffer.
6263              */
6264             @Override
6265             public void readValueFromBuffer(final ByteBuffer buffer) {
6266                 // because java doesn't support unsigned types we use the next
6267                 // type that can hold all desired values
6268                 loaderIterator.index = buffer.getInt(0);
6269             }
6270         }
6271 
6272         /**
6273          * Reads the index of a face/polygon vertex from temporal buffer using
6274          * int32 type.
6275          */
6276         private class FaceInt32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6277 
6278             /**
6279              * Reads the index of a face/polygon vertex from temporal buffer and
6280              * sets its value on current loader iterator.
6281              *
6282              * @param buffer Temporal buffer.
6283              */
6284             @Override
6285             public void readValueFromBuffer(final ByteBuffer buffer) {
6286                 loaderIterator.index = buffer.getInt(0);
6287             }
6288         }
6289 
6290         /**
6291          * Reads the index of a face/polygon vertex from temporal buffer using
6292          * uint32 type.
6293          */
6294         private class FaceUint32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6295 
6296             /**
6297              * Reads the index of a face/polygon vertex from temporal buffer and
6298              * sets its value on current loader iterator.
6299              *
6300              * @param buffer Temporal buffer.
6301              */
6302             @Override
6303             public void readValueFromBuffer(final ByteBuffer buffer) {
6304                 // because java doesn't support unsigned types we use the next
6305                 // type that can hold all desired values
6306                 loaderIterator.index = buffer.getLong(0);
6307             }
6308         }
6309 
6310         /**
6311          * Reads the index of a face/polygon vertex from temporal buffer using
6312          * float32 type.
6313          */
6314         private class FaceFloat32ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6315 
6316             /**
6317              * Reads the index of a face/polygon vertex from temporal buffer and
6318              * sets its value on current loader iterator.
6319              *
6320              * @param buffer Temporal buffer.
6321              */
6322             @Override
6323             public void readValueFromBuffer(final ByteBuffer buffer) {
6324                 final var value = buffer.getFloat(0);
6325 
6326                 loaderIterator.index = (long) value;
6327             }
6328         }
6329 
6330         /**
6331          * Reads the index of a face/polygon vertex from temporal buffer using
6332          * float64 type.
6333          */
6334         private class FaceFloat64ReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6335 
6336             /**
6337              * Reads the index of a face/polygon vertex from temporal buffer and
6338              * sets its value on current loader iterator.
6339              *
6340              * @param buffer Temporal buffer.
6341              */
6342             @Override
6343             public void readValueFromBuffer(final ByteBuffer buffer) {
6344                 final var value = buffer.getDouble(0);
6345 
6346                 loaderIterator.index = (long) value;
6347             }
6348         }
6349 
6350         /**
6351          * Reads the index of a face/polygon vertex from temporal buffer using
6352          * char type.
6353          */
6354         private class FaceCharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6355 
6356             /**
6357              * Reads the index of a face/polygon vertex from temporal buffer and
6358              * sets its value on current loader iterator.
6359              *
6360              * @param buffer Temporal buffer.
6361              */
6362             @Override
6363             public void readValueFromBuffer(final ByteBuffer buffer) {
6364                 loaderIterator.index = buffer.get(0);
6365             }
6366         }
6367 
6368         /**
6369          * Reads the index of a face/polygon vertex from temporal buffer using
6370          * uchar type.
6371          */
6372         private class FaceUcharReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6373 
6374             /**
6375              * Reads the index of a face/polygon vertex from temporal buffer and
6376              * sets its value on current loader iterator.
6377              *
6378              * @param buffer Temporal buffer.
6379              */
6380             @Override
6381             public void readValueFromBuffer(final ByteBuffer buffer) {
6382                 // because java doesn't support unsigned types we use the next
6383                 // type that can hold all desired values
6384                 loaderIterator.index = buffer.getShort(0);
6385             }
6386         }
6387 
6388         /**
6389          * Reads the index of a face/polygon vertex from temporal buffer using
6390          * short type.
6391          */
6392         private class FaceShortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6393 
6394             /**
6395              * Reads the index of a face/polygon vertex from temporal buffer and
6396              * sets its value on current loader iterator.
6397              *
6398              * @param buffer Temporal buffer.
6399              */
6400             @Override
6401             public void readValueFromBuffer(final ByteBuffer buffer) {
6402                 loaderIterator.index = buffer.getShort(0);
6403             }
6404         }
6405 
6406         /**
6407          * Reads the index of a face/polygon vertex from temporal buffer using
6408          * ushort type.
6409          */
6410         private class FaceUshortReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6411 
6412             /**
6413              * Reads the index of a face/polygon vertex from temporal buffer and
6414              * sets its value on current loader iterator.
6415              *
6416              * @param buffer Temporal buffer.
6417              */
6418             @Override
6419             public void readValueFromBuffer(final ByteBuffer buffer) {
6420                 // because java doesn't support unsigned types we use the next
6421                 // type that can hold all desired values
6422                 loaderIterator.index = buffer.getInt(0);
6423             }
6424         }
6425 
6426         /**
6427          * Reads the index of a face/polygon vertex from temporal buffer using
6428          * int type.
6429          */
6430         private class FaceIntReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6431 
6432             /**
6433              * Reads the index of a face/polygon vertex from temporal buffer and
6434              * sets its value on current loader iterator.
6435              *
6436              * @param buffer Temporal buffer.
6437              */
6438             @Override
6439             public void readValueFromBuffer(final ByteBuffer buffer) {
6440                 loaderIterator.index = buffer.getInt(0);
6441             }
6442         }
6443 
6444         /**
6445          * Reads the index of a face/polygon vertex from temporal buffer using
6446          * uint type.
6447          */
6448         private class FaceUintReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6449 
6450             /**
6451              * Reads the index of a face/polygon vertex from temporal buffer and
6452              * sets its value on current loader iterator.
6453              *
6454              * @param buffer Temporal buffer.
6455              */
6456             @Override
6457             public void readValueFromBuffer(final ByteBuffer buffer) {
6458                 // because java doesn't support unsigned types we use the next
6459                 // type that can hold all desired values
6460                 loaderIterator.index = buffer.getLong(0);
6461             }
6462         }
6463 
6464         /**
6465          * Reads the index of a face/polygon vertex from temporal buffer using
6466          * float type.
6467          */
6468         private class FaceFloatReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6469 
6470             /**
6471              * Reads the index of a face/polygon vertex from temporal buffer and
6472              * sets its value on current loader iterator.
6473              *
6474              * @param buffer Temporal buffer.
6475              */
6476             @Override
6477             public void readValueFromBuffer(final ByteBuffer buffer) {
6478                 final var value = buffer.getFloat(0);
6479 
6480                 loaderIterator.index = (long) value;
6481             }
6482         }
6483 
6484         /**
6485          * Reads the index of a face/polygon vertex from temporal buffer using
6486          * double type.
6487          */
6488         private class FaceDoubleReadValueFromBufferListener implements PLYReadValueFromBufferListener {
6489 
6490             /**
6491              * Reads the index of a face/polygon vertex from temporal buffer and
6492              * sets its value on current loader iterator.
6493              *
6494              * @param buffer Temporal buffer.
6495              */
6496             @Override
6497             public void readValueFromBuffer(final ByteBuffer buffer) {
6498                 final var value = buffer.getDouble(0);
6499 
6500                 loaderIterator.index = (long) value;
6501             }
6502         }
6503 
6504         /**
6505          * Reads an int8 from the file stream of data assuming that file is in
6506          * ascii text format.
6507          */
6508         private class AsciiInt8ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6509 
6510             /**
6511              * Reads next word of text within file at current position and
6512              * attempts to parse it into an int8 value.
6513              *
6514              * @param buffer Buffer where data will be stored.
6515              * @throws IOException if an I/O error occurs or data cannot be
6516              *                     parsed into an int8.
6517              */
6518             @Override
6519             public void readFromStream(final ByteBuffer buffer) throws IOException {
6520                 String str;
6521 
6522                 // read word
6523                 do {
6524                     str = readWordOrEmpty();
6525                     // loop to avoid empty strings
6526                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6527 
6528                 // retrieve word value
6529                 try {
6530                     final var value = Byte.parseByte(str);
6531 
6532                     // save to buffer
6533                     buffer.put(0, value);
6534                 } catch (final NumberFormatException e) {
6535                     throw new CorruptValueException(e);
6536                 }
6537             }
6538         }
6539 
6540         /**
6541          * Reads a uint8 from the file stream of data assuming that file is in
6542          * ascii text format.
6543          */
6544         private class AsciiUint8ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6545 
6546             /**
6547              * Reads next word of text within file at current position and
6548              * attempts to parse it into an uint8 value.
6549              *
6550              * @param buffer Buffer where data will be stored.
6551              * @throws IOException if an I/O error occurs or data cannot be
6552              *                     parsed into an uint8.
6553              */
6554             @Override
6555             public void readFromStream(final ByteBuffer buffer) throws IOException {
6556                 String str;
6557 
6558                 // read word
6559                 do {
6560                     str = readWordOrEmpty();
6561                     // loop to avoid empty strings
6562                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6563 
6564                 // Because Java doesn't support unsigned types we use the next type
6565                 // capable of holding all values
6566                 try {
6567                     final var value = Short.parseShort(str);
6568 
6569                     // save to buffer
6570                     buffer.putShort(0, value);
6571                 } catch (final NumberFormatException e) {
6572                     throw new CorruptValueException(e);
6573                 }
6574             }
6575         }
6576 
6577         /**
6578          * Reads an int16 from the file stream of data assuming that file is in
6579          * ascii text format.
6580          */
6581         private class AsciiInt16ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6582 
6583             /**
6584              * Reads next word of text within file at current position and
6585              * attempts to parse it into an int16 value.
6586              *
6587              * @param buffer Buffer where data will be stored.
6588              * @throws IOException if an I/O error occurs or data cannot be
6589              *                     parsed into an int16.
6590              */
6591             @Override
6592             public void readFromStream(final ByteBuffer buffer) throws IOException {
6593                 String str;
6594 
6595                 // read word
6596                 do {
6597                     str = readWordOrEmpty();
6598                     // loop to avoid empty strings
6599                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6600 
6601                 // retrieve word value
6602                 try {
6603                     final var value = Short.parseShort(str);
6604 
6605                     // save to buffer
6606                     buffer.putShort(0, value);
6607                 } catch (final NumberFormatException e) {
6608                     throw new CorruptValueException(e);
6609                 }
6610             }
6611         }
6612 
6613         /**
6614          * Reads a uint16 from the file stream of data assuming that file is in
6615          * ascii text format.
6616          */
6617         private class AsciiUint16ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6618 
6619             /**
6620              * Reads next word of text within file at current position and
6621              * attempts to parse it into an uint16 value.
6622              *
6623              * @param buffer Buffer where data will be stored.
6624              * @throws IOException if an I/O error occurs or data cannot be
6625              *                     parsed into an uint16.
6626              */
6627             @Override
6628             public void readFromStream(final ByteBuffer buffer) throws IOException {
6629                 String str;
6630 
6631                 // read word
6632                 do {
6633                     str = readWordOrEmpty();
6634                     // loop to avoid empty strings
6635                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6636 
6637                 // Because Java doesn't support unsigned types we use the next type
6638                 // capable of holding all values
6639                 try {
6640                     final var value = Integer.parseInt(str);
6641 
6642                     // save to buffer
6643                     buffer.putInt(0, value);
6644                 } catch (final NumberFormatException e) {
6645                     throw new CorruptValueException(e);
6646                 }
6647             }
6648         }
6649 
6650         /**
6651          * Reads an int32 from the file stream of data assuming that file is in
6652          * ascii text format.
6653          */
6654         private class AsciiInt32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6655 
6656             /**
6657              * Reads next word of text within file at current position and
6658              * attempts to parse it into an int32 value.
6659              *
6660              * @param buffer Buffer where data will be stored.
6661              * @throws IOException if an I/O error occurs or data cannot be
6662              *                     parsed into an int32.
6663              */
6664             @Override
6665             public void readFromStream(final ByteBuffer buffer) throws IOException {
6666                 String str;
6667 
6668                 // read word
6669                 do {
6670                     str = readWordOrEmpty();
6671                     // loop to avoid empty strings
6672                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6673 
6674                 // retrieve word value
6675                 try {
6676                     final var value = Integer.parseInt(str);
6677 
6678                     // save to buffer
6679                     buffer.putInt(0, value);
6680                 } catch (final NumberFormatException e) {
6681                     throw new CorruptValueException(e);
6682                 }
6683             }
6684         }
6685 
6686         /**
6687          * Reads a uint32 from the file stream of data assuming that file is in
6688          * ascii text format.
6689          */
6690         private class AsciiUint32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6691 
6692             /**
6693              * Reads next word of text within file at current position and
6694              * attempts to parse it into an uint32 value.
6695              *
6696              * @param buffer Buffer where data will be stored.
6697              * @throws IOException if an I/O error occurs or data cannot be
6698              *                     parsed into an uint32.
6699              */
6700             @Override
6701             public void readFromStream(final ByteBuffer buffer) throws IOException {
6702                 String str;
6703 
6704                 // read word
6705                 do {
6706                     str = readWordOrEmpty();
6707                     // loop to avoid empty strings
6708                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6709 
6710                 // Because Java doesn't support unsigned types we use the next type
6711                 // capable of holding all values
6712                 try {
6713                     final var value = Long.parseLong(str);
6714 
6715                     // save to buffer
6716                     buffer.putLong(0, value);
6717                 } catch (final NumberFormatException e) {
6718                     throw new CorruptValueException(e);
6719                 }
6720             }
6721         }
6722 
6723         /**
6724          * Reads a float32 from the file stream of data assuming that file is in
6725          * ascii text format.
6726          */
6727         private class AsciiFloat32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6728 
6729             /**
6730              * Reads next word of text within file at current position and
6731              * attempts to parse it into a float32 value.
6732              *
6733              * @param buffer Buffer where data will be stored.
6734              * @throws IOException if an I/O error occurs or data cannot be
6735              *                     parsed into an float32.
6736              */
6737             @Override
6738             public void readFromStream(final ByteBuffer buffer) throws IOException {
6739                 String str;
6740 
6741                 // read word
6742                 do {
6743                     str = readWordOrEmpty();
6744                     // loop to avoid empty strings
6745                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6746 
6747                 // retrieve word value
6748                 try {
6749                     final var value = Float.parseFloat(str);
6750 
6751                     // save to buffer
6752                     buffer.putFloat(0, value);
6753                 } catch (final NumberFormatException e) {
6754                     throw new CorruptValueException(e);
6755                 }
6756             }
6757         }
6758 
6759         /**
6760          * Reads a float64 from the file stream of data assuming that file is in
6761          * ascii text format.
6762          */
6763         private class AsciiFloat64ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6764 
6765             /**
6766              * Reads next word of text within file at current position and
6767              * attempts to parse it into a float64 value.
6768              *
6769              * @param buffer Buffer where data will be stored.
6770              * @throws IOException if an I/O error occurs or data cannot be
6771              *                     parsed into an float64.
6772              */
6773             @Override
6774             public void readFromStream(final ByteBuffer buffer) throws IOException {
6775                 String str;
6776 
6777                 // read word
6778                 do {
6779                     str = readWordOrEmpty();
6780                     // loop to avoid empty strings
6781                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6782 
6783                 // retrieve word value
6784                 try {
6785                     final var value = Double.parseDouble(str);
6786 
6787                     // save to buffer
6788                     buffer.putDouble(0, value);
6789                 } catch (final NumberFormatException e) {
6790                     throw new CorruptValueException(e);
6791                 }
6792             }
6793         }
6794 
6795         /**
6796          * Reads a char from the file stream of data assuming that file is in
6797          * ascii text format.
6798          */
6799         private class AsciiCharReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6800 
6801             /**
6802              * Reads next word of text within file at current position and
6803              * attempts to parse it into a char value.
6804              *
6805              * @param buffer Buffer where data will be stored.
6806              * @throws IOException if an I/O error occurs or data cannot be
6807              *                     parsed into a char.
6808              */
6809             @Override
6810             public void readFromStream(final ByteBuffer buffer) throws IOException {
6811                 String str;
6812 
6813                 // read word
6814                 do {
6815                     str = readWordOrEmpty();
6816                     // loop to avoid empty strings
6817                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6818 
6819                 // retrieve word value
6820                 try {
6821                     final var value = Byte.parseByte(str);
6822 
6823                     // save to buffer
6824                     buffer.put(0, value);
6825                 } catch (final NumberFormatException e) {
6826                     throw new CorruptValueException(e);
6827                 }
6828             }
6829         }
6830 
6831         /**
6832          * Reads a uchar from the file stream of data assuming that file is in
6833          * ascii text format.
6834          */
6835         private class AsciiUcharReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6836 
6837             /**
6838              * Reads next word of text within file at current position and
6839              * attempts to parse it into a uchar value.
6840              *
6841              * @param buffer Buffer where data will be stored.
6842              * @throws IOException if an I/O error occurs or data cannot be
6843              *                     parsed into a uchar.
6844              */
6845             @Override
6846             public void readFromStream(final ByteBuffer buffer) throws IOException {
6847                 String str;
6848 
6849                 // read word
6850                 do {
6851                     str = readWordOrEmpty();
6852                     // loop to avoid empty strings
6853                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6854 
6855                 // Because Java doesn't support unsigned types we use the next type
6856                 // capable of holding all values
6857                 try {
6858                     final var value = Short.parseShort(str);
6859 
6860                     // save to buffer
6861                     buffer.putShort(0, value);
6862                 } catch (final NumberFormatException e) {
6863                     throw new CorruptValueException(e);
6864                 }
6865             }
6866         }
6867 
6868         /**
6869          * Reads a short from the file stream of data assuming that file is in
6870          * ascii text format.
6871          */
6872         private class AsciiShortReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6873 
6874             /**
6875              * Reads next word of text within file at current position and
6876              * attempts to parse it into a short value.
6877              *
6878              * @param buffer Buffer where data will be stored.
6879              * @throws IOException if an I/O error occurs or data cannot be
6880              *                     parsed into a short.
6881              */
6882             @Override
6883             public void readFromStream(final ByteBuffer buffer) throws IOException {
6884                 String str;
6885 
6886                 // read word
6887                 do {
6888                     str = readWordOrEmpty();
6889                     // loop to avoid empty strings
6890                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6891 
6892                 // retrieve word value
6893                 try {
6894                     final var value = Short.parseShort(str);
6895 
6896                     // save to buffer
6897                     buffer.putShort(0, value);
6898                 } catch (final NumberFormatException e) {
6899                     throw new CorruptValueException(e);
6900                 }
6901             }
6902         }
6903 
6904         /**
6905          * Reads a ushort from the file stream of data assuming that file is in
6906          * ascii text format.
6907          */
6908         private class AsciiUshortReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6909 
6910             /**
6911              * Reads next word of text within file at current position and
6912              * attempts to parse it into a ushort value.
6913              *
6914              * @param buffer Buffer where data will be stored.
6915              * @throws IOException if an I/O error occurs or data cannot be
6916              *                     parsed into a ushort.
6917              */
6918             @Override
6919             public void readFromStream(final ByteBuffer buffer) throws IOException {
6920                 String str;
6921 
6922                 // read word
6923                 do {
6924                     str = readWordOrEmpty();
6925                     // loop to avoid empty strings
6926                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6927 
6928                 // Because Java doesn't support unsigned types we use the next type
6929                 // capable of holding all values
6930                 try {
6931                     final var value = Integer.parseInt(str);
6932 
6933                     // save to buffer
6934                     buffer.putInt(0, value);
6935                 } catch (final NumberFormatException e) {
6936                     throw new CorruptValueException(e);
6937                 }
6938             }
6939         }
6940 
6941         /**
6942          * Reads an int from the file stream of data assuming that file is in
6943          * ascii text format.
6944          */
6945         private class AsciiIntReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6946 
6947             /**
6948              * Reads next word of text within file at current position and
6949              * attempts to parse it into an int value.
6950              *
6951              * @param buffer Buffer where data will be stored.
6952              * @throws IOException if an I/O error occurs or data cannot be
6953              *                     parsed into an int.
6954              */
6955             @Override
6956             public void readFromStream(final ByteBuffer buffer) throws IOException {
6957                 String str;
6958 
6959                 // read word
6960                 do {
6961                     str = readWordOrEmpty();
6962                     // loop to avoid empty strings
6963                 } while ((str.isEmpty()) && !reader.isEndOfStream());
6964 
6965                 // retrieve word value
6966                 try {
6967                     final var value = Integer.parseInt(str);
6968 
6969                     // save to buffer
6970                     buffer.putInt(0, value);
6971                 } catch (final NumberFormatException e) {
6972                     throw new CorruptValueException(e);
6973                 }
6974             }
6975         }
6976 
6977         /**
6978          * Reads a uint from the file stream of data assuming that file is in
6979          * ascii text format.
6980          */
6981         private class AsciiUintReadValueFromStreamListener implements PLYReadValueFromStreamListener {
6982 
6983             /**
6984              * Reads next word of text within file at current position and
6985              * attempts to parse it into a uint value.
6986              *
6987              * @param buffer Buffer where data will be stored.
6988              * @throws IOException if an I/O error occurs or data cannot be
6989              *                     parsed into a uint.
6990              */
6991             @Override
6992             public void readFromStream(final ByteBuffer buffer) throws IOException {
6993                 String str;
6994 
6995                 // read word
6996                 do {
6997                     str = readWordOrEmpty();
6998                     // loop to avoid empty strings
6999                 } while ((str.isEmpty()) && !reader.isEndOfStream());
7000 
7001                 // Because Java doesn't support unsigned types we use the next type
7002                 // capable of holding all values
7003                 try {
7004                     final var value = Long.parseLong(str);
7005 
7006                     // save to buffer
7007                     buffer.putLong(0, value);
7008                 } catch (final NumberFormatException e) {
7009                     throw new CorruptValueException(e);
7010                 }
7011             }
7012         }
7013 
7014         /**
7015          * Reads a float from the file stream of data assuming that file is in
7016          * ascii text format.
7017          */
7018         private class AsciiFloatReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7019 
7020             /**
7021              * Reads next word of text within file at current position and
7022              * attempts to parse it into a float value.
7023              *
7024              * @param buffer Buffer where data will be stored.
7025              * @throws IOException if an I/O error occurs or data cannot be
7026              *                     parsed into a float.
7027              */
7028             @Override
7029             public void readFromStream(final ByteBuffer buffer) throws IOException {
7030                 String str;
7031 
7032                 // read word
7033                 do {
7034                     str = readWordOrEmpty();
7035                     // loop to avoid empty strings
7036                 } while ((str.isEmpty()) && !reader.isEndOfStream());
7037 
7038                 // retrieve word value
7039                 try {
7040                     final var value = Float.parseFloat(str);
7041 
7042                     // save to buffer
7043                     buffer.putFloat(0, value);
7044                 } catch (final NumberFormatException e) {
7045                     throw new CorruptValueException(e);
7046                 }
7047             }
7048         }
7049 
7050         /**
7051          * Reads a double from the file stream of data assuming that file is in
7052          * ascii text format.
7053          */
7054         private class AsciiDoubleReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7055 
7056             /**
7057              * Reads next word of text within file at current position and
7058              * attempts to parse it into a double value.
7059              *
7060              * @param buffer Buffer where data will be stored.
7061              * @throws IOException if an I/O error occurs or data cannot be
7062              *                     parsed into a double.
7063              */
7064             @Override
7065             public void readFromStream(final ByteBuffer buffer) throws IOException {
7066                 String str;
7067 
7068                 // read word
7069                 do {
7070                     str = readWordOrEmpty();
7071                     // loop to avoid empty strings
7072                 } while ((str.isEmpty()) && !reader.isEndOfStream());
7073 
7074                 // retrieve word value
7075                 try {
7076                     final var value = Double.parseDouble(str);
7077 
7078                     // save to buffer
7079                     buffer.putDouble(0, value);
7080                 } catch (final NumberFormatException e) {
7081                     throw new CorruptValueException(e);
7082                 }
7083             }
7084         }
7085 
7086         /**
7087          * Reads an int8 from the file stream of data assuming that file is in
7088          * binary format.
7089          */
7090         private class BinaryInt8ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7091 
7092             /**
7093              * Reads an int8 from the stream of data at current file position
7094              * and stores the result into provided byte buffer.
7095              *
7096              * @param buffer Buffer where data will be stored.
7097              * @throws IOException if an I/O error occurs.
7098              */
7099             @Override
7100             public void readFromStream(final ByteBuffer buffer) throws IOException {
7101                 final var value = reader.readByte();
7102 
7103                 // save to buffer
7104                 buffer.put(0, value);
7105             }
7106         }
7107 
7108         /**
7109          * Reads a uint8 from the file stream of data assuming that file is in
7110          * binary format.
7111          */
7112         private class BinaryUint8ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7113 
7114             /**
7115              * Reads a uint8 from the stream of data at current file position
7116              * and stores the result into provided byte buffer.
7117              *
7118              * @param buffer Buffer where data will be stored.
7119              * @throws IOException if an I/O error occurs.
7120              */
7121             @Override
7122             public void readFromStream(final ByteBuffer buffer) throws IOException {
7123                 // Because Java doesn't support unsigned types, we use the next
7124                 // type that can hold all values
7125                 final var value = reader.readUnsignedByte();
7126 
7127                 // save to buffer
7128                 buffer.putShort(0, value);
7129             }
7130         }
7131 
7132         /**
7133          * Reads a char from the file stream of data assuming that file is in
7134          * binary format.
7135          */
7136         private class BinaryCharReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7137 
7138             /**
7139              * Reads a char from the stream of data at current file position
7140              * and stores the result into provided byte buffer.
7141              *
7142              * @param buffer Buffer where data will be stored.
7143              * @throws IOException if an I/O error occurs.
7144              */
7145             @Override
7146             public void readFromStream(final ByteBuffer buffer) throws IOException {
7147                 final var value = reader.readByte();
7148 
7149                 // save to buffer
7150                 buffer.put(0, value);
7151             }
7152         }
7153 
7154         /**
7155          * Reads a uchar from the file stream of data assuming that file is in
7156          * binary format.
7157          */
7158         private class BinaryUcharReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7159 
7160             /**
7161              * Reads a uchar from the stream of data at current file position
7162              * and stores the result into provided byte buffer.
7163              *
7164              * @param buffer Buffer where data will be stored.
7165              * @throws IOException if an I/O error occurs.
7166              */
7167             @Override
7168             public void readFromStream(final ByteBuffer buffer) throws IOException {
7169                 // Because Java doesn't support unsigned types, we use the next
7170                 // type that can hold all values
7171                 final var value = reader.readUnsignedByte();
7172 
7173                 // save to buffer
7174                 buffer.putShort(0, value);
7175             }
7176         }
7177 
7178         /**
7179          * Reads an int16 from the file stream of data assuming that file is in
7180          * little endian binary format.
7181          */
7182         private class BinaryLittleEndianInt16ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7183 
7184             /**
7185              * Reads an int16 from the stream of data at current file position
7186              * and stores the result into provided byte buffer. Stream data is
7187              * assumed to be in little endian format.
7188              *
7189              * @param buffer Buffer where data will be stored.
7190              * @throws IOException if an I/O error occurs.
7191              */
7192             @Override
7193             public void readFromStream(final ByteBuffer buffer) throws IOException {
7194                 final var value = reader.readShort(EndianType.LITTLE_ENDIAN_TYPE);
7195 
7196                 // save to buffer
7197                 buffer.putShort(0, value);
7198             }
7199         }
7200 
7201         /**
7202          * Reads a uint16 from the file stream of data assuming that file is in
7203          * little endian binary format.
7204          */
7205         private class BinaryLittleEndianUint16ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7206 
7207             /**
7208              * Reads a uint16 from the stream of data at current file position
7209              * and stores the result into provided byte buffer. Stream data is
7210              * assumed to be in little endian format.
7211              *
7212              * @param buffer Buffer where data will be stored.
7213              * @throws IOException if an I/O error occurs.
7214              */
7215             @Override
7216             public void readFromStream(final ByteBuffer buffer) throws IOException {
7217                 // Because Java doesn't support unsigned types, we use the next
7218                 // type that can hold all values
7219                 final var value = reader.readUnsignedShort(EndianType.LITTLE_ENDIAN_TYPE);
7220 
7221                 // save to buffer
7222                 buffer.putInt(0, value);
7223             }
7224         }
7225 
7226         /**
7227          * Reads an int32 from the file stream of data assuming that file is in
7228          * little endian binary format.
7229          */
7230         private class BinaryLittleEndianInt32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7231 
7232             /**
7233              * Reads an int32 from the stream of data at current file position
7234              * and stores the result into provided byte buffer. Stream data is
7235              * assumed to be in little endian format.
7236              *
7237              * @param buffer Buffer where data will be stored.
7238              * @throws IOException if an I/O error occurs.
7239              */
7240             @Override
7241             public void readFromStream(final ByteBuffer buffer) throws IOException {
7242                 final var value = reader.readInt(EndianType.LITTLE_ENDIAN_TYPE);
7243 
7244                 // save to buffer
7245                 buffer.putInt(0, value);
7246             }
7247         }
7248 
7249         /**
7250          * Reads a uint32 from the file stream of data assuming that file is in
7251          * little endian binary format.
7252          */
7253         private class BinaryLittleEndianUint32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7254 
7255             /**
7256              * Reads a uint32 from the stream of data at current file position
7257              * and stores the result into provided byte buffer. Stream data is
7258              * assumed to be in little endian format.
7259              *
7260              * @param buffer Buffer where data will be stored.
7261              * @throws IOException if an I/O error occurs.
7262              */
7263             @Override
7264             public void readFromStream(final ByteBuffer buffer) throws IOException {
7265                 // Because Java doesn't support unsigned types, we use the next
7266                 // type that can hold all values
7267                 final var value = reader.readUnsignedInt(EndianType.LITTLE_ENDIAN_TYPE);
7268 
7269                 // save to buffer
7270                 buffer.putLong(0, value);
7271             }
7272         }
7273 
7274         /**
7275          * Reads a float32 from the file stream of data assuming that file is in
7276          * little endian binary format.
7277          */
7278         private class BinaryLittleEndianFloat32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7279 
7280             /**
7281              * Reads a float32 from the stream of data at current file position
7282              * and stores the result into provided byte buffer. Stream data is
7283              * assumed to be in little endian format.
7284              *
7285              * @param buffer Buffer where data will be stored.
7286              * @throws IOException if an I/O error occurs.
7287              */
7288             @Override
7289             public void readFromStream(final ByteBuffer buffer) throws IOException {
7290                 final var value = reader.readFloat(EndianType.LITTLE_ENDIAN_TYPE);
7291 
7292                 // save to buffer
7293                 buffer.putFloat(0, value);
7294             }
7295         }
7296 
7297         /**
7298          * Reads a float64 from the file stream of data assuming that file is in
7299          * little endian binary format.
7300          */
7301         private class BinaryLittleEndianFloat64ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7302 
7303             /**
7304              * Reads a float64 from the stream of data at current file position
7305              * and stores the result into provided byte buffer. Stream data is
7306              * assumed to be in little endian format.
7307              *
7308              * @param buffer Buffer where data will be stored.
7309              * @throws IOException if an I/O error occurs.
7310              */
7311             @Override
7312             public void readFromStream(final ByteBuffer buffer) throws IOException {
7313                 final var value = reader.readDouble(EndianType.LITTLE_ENDIAN_TYPE);
7314 
7315                 // save to buffer
7316                 buffer.putDouble(0, value);
7317             }
7318         }
7319 
7320         /**
7321          * Reads a short from the file stream of data assuming that file is in
7322          * little endian binary format.
7323          */
7324         private class BinaryLittleEndianShortReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7325 
7326             /**
7327              * Reads a short from the stream of data at current file position
7328              * and stores the result into provided byte buffer. Stream data is
7329              * assumed to be in little endian format.
7330              *
7331              * @param buffer Buffer where data will be stored.
7332              * @throws IOException if an I/O error occurs.
7333              */
7334             @Override
7335             public void readFromStream(final ByteBuffer buffer) throws IOException {
7336                 final var value = reader.readShort(EndianType.LITTLE_ENDIAN_TYPE);
7337 
7338                 // save to buffer
7339                 buffer.putShort(0, value);
7340             }
7341         }
7342 
7343         /**
7344          * Reads a ushort from the file stream of data assuming that file is in
7345          * little endian binary format.
7346          */
7347         private class BinaryLittleEndianUshortReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7348 
7349             /**
7350              * Reads a ushort from the stream of data at current file position
7351              * and stores the result into provided byte buffer. Stream data is
7352              * assumed to be in little endian format.
7353              *
7354              * @param buffer Buffer where data will be stored.
7355              * @throws IOException if an I/O error occurs.
7356              */
7357             @Override
7358             public void readFromStream(final ByteBuffer buffer) throws IOException {
7359                 // Because Java doesn't support unsigned types, we use the next
7360                 // type that can hold all values
7361                 final var value = reader.readUnsignedShort(EndianType.LITTLE_ENDIAN_TYPE);
7362 
7363                 // save to buffer
7364                 buffer.putInt(0, value);
7365             }
7366         }
7367 
7368         /**
7369          * Reads an int from the file stream of data assuming that file is in
7370          * little endian binary format.
7371          */
7372         private class BinaryLittleEndianIntReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7373 
7374             /**
7375              * Reads an int from the stream of data at current file position
7376              * and stores the result into provided byte buffer. Stream data is
7377              * assumed to be in little endian format.
7378              *
7379              * @param buffer Buffer where data will be stored.
7380              * @throws IOException if an I/O error occurs.
7381              */
7382             @Override
7383             public void readFromStream(final ByteBuffer buffer) throws IOException {
7384                 final var value = reader.readInt(EndianType.LITTLE_ENDIAN_TYPE);
7385 
7386                 // save to buffer
7387                 buffer.putInt(0, value);
7388             }
7389         }
7390 
7391         /**
7392          * Reads a uint from the file stream of data assuming that file is in
7393          * little endian binary format.
7394          */
7395         private class BinaryLittleEndianUintReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7396 
7397             /**
7398              * Reads a uint from the stream of data at current file position
7399              * and stores the result into provided byte buffer. Stream data is
7400              * assumed to be in little endian format.
7401              *
7402              * @param buffer Buffer where data will be stored.
7403              * @throws IOException if an I/O error occurs.
7404              */
7405             @Override
7406             public void readFromStream(final ByteBuffer buffer) throws IOException {
7407                 // Because Java doesn't support unsigned types, we use the next
7408                 // type that can hold all values
7409                 final var value = reader.readUnsignedInt(EndianType.LITTLE_ENDIAN_TYPE);
7410 
7411                 // save to buffer
7412                 buffer.putLong(0, value);
7413             }
7414         }
7415 
7416         /**
7417          * Reads a float from the file stream of data assuming that file is in
7418          * little endian binary format.
7419          */
7420         private class BinaryLittleEndianFloatReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7421 
7422             /**
7423              * Reads a float from the stream of data at current file position
7424              * and stores the result into provided byte buffer. Stream data is
7425              * assumed to be in little endian format.
7426              *
7427              * @param buffer Buffer where data will be stored.
7428              * @throws IOException if an I/O error occurs.
7429              */
7430             @Override
7431             public void readFromStream(final ByteBuffer buffer) throws IOException {
7432                 final var value = reader.readFloat(EndianType.LITTLE_ENDIAN_TYPE);
7433 
7434                 // save to buffer
7435                 buffer.putFloat(0, value);
7436             }
7437         }
7438 
7439         /**
7440          * Reads a double from the file stream of data assuming that file is in
7441          * little endian binary format.
7442          */
7443         private class BinaryLittleEndianDoubleReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7444 
7445             /**
7446              * Reads a double from the stream of data at current file position
7447              * and stores the result into provided byte buffer. Stream data is
7448              * assumed to be in little endian format.
7449              *
7450              * @param buffer Buffer where data will be stored.
7451              * @throws IOException if an I/O error occurs.
7452              */
7453             @Override
7454             public void readFromStream(final ByteBuffer buffer) throws IOException {
7455                 final var value = reader.readDouble(EndianType.LITTLE_ENDIAN_TYPE);
7456 
7457                 // save to buffer
7458                 buffer.putDouble(0, value);
7459             }
7460         }
7461 
7462         /**
7463          * Reads an int16 from the file stream of data assuming that file is in
7464          * big endian binary format.
7465          */
7466         private class BinaryBigEndianInt16ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7467 
7468             /**
7469              * Reads an int16 from the stream of data at current file position
7470              * and stores the result into provided byte buffer. Stream data is
7471              * assumed to be in big endian format.
7472              *
7473              * @param buffer Buffer where data will be stored.
7474              * @throws IOException if an I/O error occurs.
7475              */
7476             @Override
7477             public void readFromStream(final ByteBuffer buffer) throws IOException {
7478                 final var value = reader.readShort(EndianType.BIG_ENDIAN_TYPE);
7479 
7480                 // save to buffer
7481                 buffer.putShort(0, value);
7482             }
7483         }
7484 
7485         /**
7486          * Reads a uint16 from the file stream of data assuming that file is in
7487          * big endian binary format.
7488          */
7489         private class BinaryBigEndianUint16ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7490 
7491             /**
7492              * Reads a uint16 from the stream of data at current file position
7493              * and stores the result into provided byte buffer. Stream data is
7494              * assumed to be in big endian format.
7495              *
7496              * @param buffer Buffer where data will be stored.
7497              * @throws IOException if an I/O error occurs.
7498              */
7499             @Override
7500             public void readFromStream(final ByteBuffer buffer) throws IOException {
7501                 // Because Java doesn't support unsigned types, we use the next
7502                 // type that can hold all values
7503                 final var value = reader.readUnsignedShort(EndianType.BIG_ENDIAN_TYPE);
7504 
7505                 // save to buffer
7506                 buffer.putInt(0, value);
7507             }
7508         }
7509 
7510         /**
7511          * Reads an int32 from the file stream of data assuming that file is in
7512          * big endian binary format.
7513          */
7514         private class BinaryBigEndianInt32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7515 
7516             /**
7517              * Reads an int32 from the stream of data at current file position
7518              * and stores the result into provided byte buffer. Stream data is
7519              * assumed to be in big endian format.
7520              *
7521              * @param buffer Buffer where data will be stored.
7522              * @throws IOException if an I/O error occurs.
7523              */
7524             @Override
7525             public void readFromStream(final ByteBuffer buffer) throws IOException {
7526                 final var value = reader.readInt(EndianType.BIG_ENDIAN_TYPE);
7527 
7528                 // save to buffer
7529                 buffer.putInt(0, value);
7530             }
7531         }
7532 
7533         /**
7534          * Reads a uint32 from the file stream of data assuming that file is in
7535          * big endian binary format.
7536          */
7537         private class BinaryBigEndianUint32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7538 
7539             /**
7540              * Reads a uint32 from the stream of data at current file position
7541              * and stores the result into provided byte buffer. Stream data is
7542              * assumed to be in big endian format.
7543              *
7544              * @param buffer Buffer where data will be stored.
7545              * @throws IOException if an I/O error occurs.
7546              */
7547             @Override
7548             public void readFromStream(final ByteBuffer buffer) throws IOException {
7549                 // Because Java doesn't support unsigned types, we use the next
7550                 // type that can hold all values
7551                 final var value = reader.readUnsignedInt(EndianType.BIG_ENDIAN_TYPE);
7552 
7553                 // save to buffer
7554                 buffer.putLong(0, value);
7555             }
7556         }
7557 
7558         /**
7559          * Reads a float32 from the file stream of data assuming that file is in
7560          * big endian binary format.
7561          */
7562         private class BinaryBigEndianFloat32ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7563 
7564             /**
7565              * Reads a float32 from the stream of data at current file position
7566              * and stores the result into provided byte buffer. Stream data is
7567              * assumed to be in big endian format.
7568              *
7569              * @param buffer Buffer where data will be stored.
7570              * @throws IOException if an I/O error occurs.
7571              */
7572             @Override
7573             public void readFromStream(final ByteBuffer buffer) throws IOException {
7574                 final var value = reader.readFloat(EndianType.BIG_ENDIAN_TYPE);
7575 
7576                 // save to buffer
7577                 buffer.putFloat(0, value);
7578             }
7579         }
7580 
7581         /**
7582          * Reads a float64 from the file stream of data assuming that file is in
7583          * big endian binary format.
7584          */
7585         private class BinaryBigEndianFloat64ReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7586 
7587             /**
7588              * Reads a float64 from the stream of data at current file position
7589              * and stores the result into provided byte buffer. Stream data is
7590              * assumed to be in big endian format.
7591              *
7592              * @param buffer Buffer where data will be stored.
7593              * @throws IOException if an I/O error occurs.
7594              */
7595             @Override
7596             public void readFromStream(final ByteBuffer buffer) throws IOException {
7597                 final var value = reader.readDouble(EndianType.BIG_ENDIAN_TYPE);
7598 
7599                 // save to buffer
7600                 buffer.putDouble(0, value);
7601             }
7602         }
7603 
7604         /**
7605          * Reads a short from the file stream of data assuming that file is in
7606          * big endian binary format.
7607          */
7608         private class BinaryBigEndianShortReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7609 
7610             /**
7611              * Reads a short from the stream of data at current file position
7612              * and stores the result into provided byte buffer. Stream data is
7613              * assumed to be in big endian format.
7614              *
7615              * @param buffer Buffer where data will be stored.
7616              * @throws IOException if an I/O error occurs.
7617              */
7618             @Override
7619             public void readFromStream(final ByteBuffer buffer) throws IOException {
7620                 final var value = reader.readShort(EndianType.BIG_ENDIAN_TYPE);
7621 
7622                 // save to buffer
7623                 buffer.putShort(0, value);
7624             }
7625         }
7626 
7627         /**
7628          * Reads a ushort from the file stream of data assuming that file is in
7629          * big endian binary format.
7630          */
7631         private class BinaryBigEndianUshortReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7632 
7633             /**
7634              * Reads a ushort from the stream of data at current file position
7635              * and stores the result into provided byte buffer. Stream data is
7636              * assumed to be in big endian format.
7637              *
7638              * @param buffer Buffer where data will be stored.
7639              * @throws IOException if an I/O error occurs.
7640              */
7641             @Override
7642             public void readFromStream(final ByteBuffer buffer) throws IOException {
7643                 // Because Java doesn't support unsigned types, we use the next
7644                 // type that can hold all values
7645                 final var value = reader.readUnsignedShort(EndianType.BIG_ENDIAN_TYPE);
7646 
7647                 // save to buffer
7648                 buffer.putInt(0, value);
7649             }
7650         }
7651 
7652         /**
7653          * Reads an int from the file stream of data assuming that file is in
7654          * big endian binary format.
7655          */
7656         private class BinaryBigEndianIntReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7657 
7658             /**
7659              * Reads an int from the stream of data at current file position
7660              * and stores the result into provided byte buffer. Stream data is
7661              * assumed to be in big endian format.
7662              *
7663              * @param buffer Buffer where data will be stored.
7664              * @throws IOException if an I/O error occurs.
7665              */
7666             @Override
7667             public void readFromStream(final ByteBuffer buffer) throws IOException {
7668                 final var value = reader.readInt(EndianType.BIG_ENDIAN_TYPE);
7669 
7670                 // save to buffer
7671                 buffer.putInt(0, value);
7672             }
7673         }
7674 
7675         /**
7676          * Reads a uint from the file stream of data assuming that file is in
7677          * big endian binary format.
7678          */
7679         private class BinaryBigEndianUintReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7680 
7681             /**
7682              * Reads a uint from the stream of data at current file position
7683              * and stores the result into provided byte buffer. Stream data is
7684              * assumed to be in big endian format.
7685              *
7686              * @param buffer Buffer where data will be stored.
7687              * @throws IOException if an I/O error occurs.
7688              */
7689             @Override
7690             public void readFromStream(final ByteBuffer buffer) throws IOException {
7691                 // Because Java doesn't support unsigned types, we use the next
7692                 // type that can hold all values
7693                 final var value = reader.readUnsignedInt(EndianType.BIG_ENDIAN_TYPE);
7694 
7695                 // save to buffer
7696                 buffer.putLong(0, value);
7697             }
7698         }
7699 
7700         /**
7701          * Reads a float from the file stream of data assuming that file is in
7702          * big endian binary format.
7703          */
7704         private class BinaryBigEndianFloatReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7705 
7706             /**
7707              * Reads a float from the stream of data at current file position
7708              * and stores the result into provided byte buffer. Stream data is
7709              * assumed to be in big endian format.
7710              *
7711              * @param buffer Buffer where data will be stored.
7712              * @throws IOException if an I/O error occurs.
7713              */
7714             @Override
7715             public void readFromStream(final ByteBuffer buffer) throws IOException {
7716                 final var value = reader.readFloat(EndianType.BIG_ENDIAN_TYPE);
7717 
7718                 // save to buffer
7719                 buffer.putFloat(0, value);
7720             }
7721         }
7722 
7723         /**
7724          * Reads a double from the file stream of data assuming that file is in
7725          * big endian binary format.
7726          */
7727         private class BinaryBigEndianDoubleReadValueFromStreamListener implements PLYReadValueFromStreamListener {
7728 
7729             /**
7730              * Reads a double from the stream of data at current file position
7731              * and stores the result into provided byte buffer. Stream data is
7732              * assumed to be in big endian format.
7733              *
7734              * @param buffer Buffer where data will be stored.
7735              * @throws IOException if an I/O error occurs.
7736              */
7737             @Override
7738             public void readFromStream(final ByteBuffer buffer) throws IOException {
7739                 final var value = reader.readDouble(EndianType.BIG_ENDIAN_TYPE);
7740 
7741                 // save to buffer
7742                 buffer.putDouble(0, value);
7743             }
7744         }
7745 
7746         /**
7747          * Reads length value of a list header element from temporal buffer of
7748          * data assuming it has int8 data type.
7749          */
7750         private class FaceInt8ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7751 
7752             /**
7753              * Reads length value of a list header element from temporal buffer
7754              * of data assuming it has int8 data type. Value read from buffer
7755              * will be stored into this PLY loader iterator.
7756              *
7757              * @param buffer Temporal buffer of data.
7758              */
7759             @Override
7760             public void readValueFromBuffer(final ByteBuffer buffer) {
7761                 loaderIterator.listElems = buffer.get(0);
7762             }
7763         }
7764 
7765         /**
7766          * Reads length value of a list header element from temporal buffer of
7767          * data assuming it has uint8 data type.
7768          */
7769         private class FaceUint8ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7770 
7771             /**
7772              * Reads length value of a list header element from temporal buffer
7773              * of data assuming it has uint8 data type. Value read from buffer
7774              * will be stored into this PLY loader iterator.
7775              *
7776              * @param buffer Temporal buffer of data.
7777              */
7778             @Override
7779             public void readValueFromBuffer(final ByteBuffer buffer) {
7780                 // Because Jave doesn't support unsigned types, we use next
7781                 // type capable of holding all values
7782                 loaderIterator.listElems = buffer.getShort(0);
7783             }
7784         }
7785 
7786         /**
7787          * Reads length value of a list header element from temporal buffer of
7788          * data assuming it has int16 data type.
7789          */
7790         private class FaceInt16ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7791 
7792             /**
7793              * Reads length value of a list header element from temporal buffer
7794              * of data assuming it has int16 data type. Value read from buffer
7795              * will be stored into this PLY loader iterator.
7796              *
7797              * @param buffer Temporal buffer of data.
7798              */
7799             @Override
7800             public void readValueFromBuffer(final ByteBuffer buffer) {
7801                 loaderIterator.listElems = buffer.getShort(0);
7802             }
7803         }
7804 
7805         /**
7806          * Reads length value of a list header element from temporal buffer of
7807          * data assuming it has uint16 data type.
7808          */
7809         private class FaceUint16ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7810 
7811             /**
7812              * Reads length value of a list header element from temporal buffer
7813              * of data assuming it has uint16 data type. Value read from buffer
7814              * will be stored into this PLY loader iterator.
7815              *
7816              * @param buffer Temporal buffer of data.
7817              */
7818             @Override
7819             public void readValueFromBuffer(final ByteBuffer buffer) {
7820                 // Because Jave doesn't support unsigned types, we use next
7821                 // type capable of holding all values
7822                 loaderIterator.listElems = buffer.getInt(0);
7823             }
7824         }
7825 
7826         /**
7827          * Reads length value of a list header element from temporal buffer of
7828          * data assuming it has int32 data type.
7829          */
7830         private class FaceInt32ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7831 
7832             /**
7833              * Reads length value of a list header element from temporal buffer
7834              * of data assuming it has int32 data type. Value read from buffer
7835              * will be stored into this PLY loader iterator
7836              *
7837              * @param buffer Temporal buffer of data.
7838              */
7839             @Override
7840             public void readValueFromBuffer(final ByteBuffer buffer) {
7841                 loaderIterator.listElems = buffer.getInt(0);
7842             }
7843         }
7844 
7845         /**
7846          * Reads length value of a list header element from temporal buffer of
7847          * data assuming it has uint32 data type.
7848          */
7849         private class FaceUint32ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7850 
7851             /**
7852              * Reads length value of a list header element from temporal buffer
7853              * of data assuming it has uint32 data type. Value read from buffer
7854              * will be stored into this PLY loader iterator
7855              *
7856              * @param buffer Temporal buffer of data.
7857              */
7858             @Override
7859             public void readValueFromBuffer(final ByteBuffer buffer) {
7860                 // Because Jave doesn't support unsigned types, we use next
7861                 // type capable of holding all values
7862                 final var value = buffer.getLong(0);
7863 
7864                 loaderIterator.listElems = (int) value;
7865             }
7866         }
7867 
7868         /**
7869          * Reads length value of a list header element from temporal buffer of
7870          * data assuming it has float32 data type.
7871          */
7872         private class FaceFloat32ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7873 
7874             /**
7875              * Reads length value of a list header element from temporal buffer
7876              * of data assuming it has float32 data type. Value read from buffer
7877              * will be stored into this PLY loader iterator.
7878              *
7879              * @param buffer Temporal buffer of data.
7880              */
7881             @Override
7882             public void readValueFromBuffer(final ByteBuffer buffer) {
7883                 final var value = buffer.getFloat(0);
7884 
7885                 loaderIterator.listElems = (int) value;
7886             }
7887         }
7888 
7889         /**
7890          * Reads length value of a list header element from temporal buffer of
7891          * data assuming it has float64 data type.
7892          */
7893         private class FaceFloat64ReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7894 
7895             /**
7896              * Reads length value of a list header element from temporal buffer
7897              * of data assuming it has float64 data type. Value read from buffer
7898              * will be stored into this PLY loader iterator.
7899              *
7900              * @param buffer Temporal buffer of data.
7901              */
7902             @Override
7903             public void readValueFromBuffer(final ByteBuffer buffer) {
7904                 final var value = buffer.getDouble(0);
7905 
7906                 loaderIterator.listElems = (int) value;
7907             }
7908         }
7909 
7910         /**
7911          * Reads length value of a list header element from temporal buffer of
7912          * data assuming it has char data type.
7913          */
7914         private class FaceCharReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7915 
7916             /**
7917              * Reads length value of a list header element from temporal buffer
7918              * of data assuming it has char data type. Value read from buffer
7919              * will be stored into this PLY loader iterator.
7920              *
7921              * @param buffer Temporal buffer of data.
7922              */
7923             @Override
7924             public void readValueFromBuffer(final ByteBuffer buffer) {
7925                 loaderIterator.listElems = buffer.get(0);
7926             }
7927         }
7928 
7929         /**
7930          * Reads length value of a list header element from temporal buffer of
7931          * data assuming it has uchar data type.
7932          */
7933         private class FaceUcharReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7934 
7935             /**
7936              * Reads length value of a list header element from temporal buffer
7937              * of data assuming it has uchar data type. Value read from buffer
7938              * will be stored into this PLY loader iterator.
7939              *
7940              * @param buffer Temporal buffer of data.
7941              */
7942             @Override
7943             public void readValueFromBuffer(final ByteBuffer buffer) {
7944                 // Because Jave doesn't support unsigned types, we use next
7945                 // type capable of holding all values
7946                 loaderIterator.listElems = buffer.getShort(0);
7947             }
7948         }
7949 
7950         /**
7951          * Reads length value of a list header element from temporal buffer of
7952          * data assuming it has short data type.
7953          */
7954         private class FaceShortReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7955 
7956             /**
7957              * Reads length value of a list header element from temporal buffer
7958              * of data assuming it has short data type. Value read from buffer
7959              * will be stored into this PLY loader iterator.
7960              *
7961              * @param buffer Temporal buffer of data.
7962              */
7963             @Override
7964             public void readValueFromBuffer(final ByteBuffer buffer) {
7965                 loaderIterator.listElems = buffer.getShort(0);
7966             }
7967         }
7968 
7969         /**
7970          * Reads length value of a list header element from temporal buffer of
7971          * data assuming it has ushort data type.
7972          */
7973         private class FaceUshortReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7974 
7975             /**
7976              * Reads length value of a list header element from temporal buffer
7977              * of data assuming it has ushort data type. Value read from buffer
7978              * will be stored into this PLY loader iterator.
7979              *
7980              * @param buffer Temporal buffer of data.
7981              */
7982             @Override
7983             public void readValueFromBuffer(final ByteBuffer buffer) {
7984                 // Because Jave doesn't support unsigned types, we use next
7985                 // type capable of holding all values
7986                 loaderIterator.listElems = buffer.getInt(0);
7987             }
7988         }
7989 
7990         /**
7991          * Reads length value of a list header element from temporal buffer of
7992          * data assuming it has int data type.
7993          */
7994         private class FaceIntReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
7995 
7996             /**
7997              * Reads length value of a list header element from temporal buffer
7998              * of data assuming it has int data type. Value read from buffer
7999              * will be stored into this PLY loader iterator.
8000              *
8001              * @param buffer Temporal buffer of data.
8002              */
8003             @Override
8004             public void readValueFromBuffer(final ByteBuffer buffer) {
8005                 loaderIterator.listElems = buffer.getInt(0);
8006             }
8007         }
8008 
8009         /**
8010          * Reads length value of a list header element from temporal buffer of
8011          * data assuming it has uint data type.
8012          */
8013         private class FaceUintReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
8014 
8015             /**
8016              * Reads length value of a list header element from temporal buffer
8017              * of data assuming it has uint data type. Value read from buffer
8018              * will be stored into this PLY loader iterator.
8019              *
8020              * @param buffer Temporal buffer of data.
8021              */
8022             @Override
8023             public void readValueFromBuffer(final ByteBuffer buffer) {
8024                 // Because Jave doesn't support unsigned types, we use next
8025                 // type capable of holding all values
8026                 final var value = buffer.getLong(0);
8027 
8028                 loaderIterator.listElems = (int) value;
8029             }
8030         }
8031 
8032         /**
8033          * Reads length value of a list header element from temporal buffer of
8034          * data assuming it has float data type.
8035          */
8036         private class FaceFloatReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
8037 
8038             /**
8039              * Reads length value of a list header element from temporal buffer
8040              * of data assuming it has float data type. Value read from buffer
8041              * will be stored into this PLY loader iterator.
8042              *
8043              * @param buffer Temporal buffer of data.
8044              */
8045             @Override
8046             public void readValueFromBuffer(final ByteBuffer buffer) {
8047                 final var value = buffer.getFloat(0);
8048 
8049                 loaderIterator.listElems = (int) value;
8050             }
8051         }
8052 
8053         /**
8054          * Reads length value of a list header element from temporal buffer of
8055          * data assuming it has double data type.
8056          */
8057         private class FaceDoubleReadLengthValueFromBufferListener implements PLYReadValueFromBufferListener {
8058 
8059             /**
8060              * Reads length value of a list header element from temporal buffer
8061              * of data assuming it has double data type. Value read from buffer
8062              * will be stored into this PLY loader iterator.
8063              *
8064              * @param buffer Temporal buffer of data.
8065              */
8066             @Override
8067             public void readValueFromBuffer(final ByteBuffer buffer) {
8068                 final var value = buffer.getDouble(0);
8069 
8070                 loaderIterator.listElems = (int) value;
8071             }
8072         }
8073 
8074         /**
8075          * Sets the listener to read data from the file stream for a given
8076          * PLY header property and using provided storage mode.
8077          *
8078          * @param property    A PLY header property.
8079          * @param storageMode Storage mode of file.
8080          * @throws NotAvailableException Raised if the listener cannot be set
8081          *                               for provided property and storage mode.
8082          */
8083         private void setReadValueFromStreamListener(final PropertyPLY property, final PLYStorageMode storageMode)
8084                 throws NotAvailableException {
8085             property.setReadValueFromStreamListener(getReadFromStreamListener(property.getValueType(), storageMode));
8086         }
8087 
8088         /**
8089          * Sets the listener to read length value of a property from the file
8090          * stream for a given PLY header property and using provided storage
8091          * mode.
8092          *
8093          * @param property    A PLY header property.
8094          * @param storageMode Storage mode of file.
8095          * @throws NotAvailableException Raised if the listener cannot be set
8096          *                               for provided property and storage mode.
8097          */
8098         private void setReadLengthValueFromStreamListener(
8099                 final PropertyPLY property, final PLYStorageMode storageMode) throws NotAvailableException {
8100             property.setReadLengthValueFromStreamListener(
8101                     getReadFromStreamListener(property.getLengthType(), storageMode));
8102         }
8103 
8104         /**
8105          * Returns a listener to read data from the file stream using provided
8106          * data type (int8, uint8, int16, uint16, etc.) and storage mode (ascii,
8107          * little endian or big endian).
8108          *
8109          * @param dataType    Data type to read.
8110          * @param storageMode Storage mode of file.
8111          * @return A listener.
8112          */
8113         private PLYReadValueFromStreamListener getReadFromStreamListener(
8114                 final DataTypePLY dataType, final PLYStorageMode storageMode) {
8115             return switch (dataType) {
8116                 case PLY_INT8 -> switch (storageMode) {
8117                     case PLY_ASCII -> new AsciiInt8ReadValueFromStreamListener();
8118                     case PLY_LITTLE_ENDIAN, PLY_BIG_ENDIAN -> new BinaryInt8ReadValueFromStreamListener();
8119                 };
8120                 case PLY_UINT8 -> switch (storageMode) {
8121                     case PLY_ASCII -> new AsciiUint8ReadValueFromStreamListener();
8122                     case PLY_LITTLE_ENDIAN, PLY_BIG_ENDIAN -> new BinaryUint8ReadValueFromStreamListener();
8123                 };
8124                 case PLY_INT16 -> switch (storageMode) {
8125                     case PLY_ASCII -> new AsciiInt16ReadValueFromStreamListener();
8126                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianInt16ReadValueFromStreamListener();
8127                     case PLY_BIG_ENDIAN -> new BinaryBigEndianInt16ReadValueFromStreamListener();
8128                 };
8129                 case PLY_UINT16 -> switch (storageMode) {
8130                     case PLY_ASCII -> new AsciiUint16ReadValueFromStreamListener();
8131                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianUint16ReadValueFromStreamListener();
8132                     case PLY_BIG_ENDIAN -> new BinaryBigEndianUint16ReadValueFromStreamListener();
8133                 };
8134                 case PLY_INT32 -> switch (storageMode) {
8135                     case PLY_ASCII -> new AsciiInt32ReadValueFromStreamListener();
8136                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianInt32ReadValueFromStreamListener();
8137                     case PLY_BIG_ENDIAN -> new BinaryBigEndianInt32ReadValueFromStreamListener();
8138                 };
8139                 case PLY_UINT32 -> switch (storageMode) {
8140                     case PLY_ASCII -> new AsciiUint32ReadValueFromStreamListener();
8141                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianUint32ReadValueFromStreamListener();
8142                     case PLY_BIG_ENDIAN -> new BinaryBigEndianUint32ReadValueFromStreamListener();
8143                 };
8144                 case PLY_FLOAT32 -> switch (storageMode) {
8145                     case PLY_ASCII -> new AsciiFloat32ReadValueFromStreamListener();
8146                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianFloat32ReadValueFromStreamListener();
8147                     case PLY_BIG_ENDIAN -> new BinaryBigEndianFloat32ReadValueFromStreamListener();
8148                 };
8149                 case PLY_FLOAT64 -> switch (storageMode) {
8150                     case PLY_ASCII -> new AsciiFloat64ReadValueFromStreamListener();
8151                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianFloat64ReadValueFromStreamListener();
8152                     case PLY_BIG_ENDIAN -> new BinaryBigEndianFloat64ReadValueFromStreamListener();
8153                 };
8154                 case PLY_CHAR -> switch (storageMode) {
8155                     case PLY_ASCII -> new AsciiCharReadValueFromStreamListener();
8156                     case PLY_LITTLE_ENDIAN, PLY_BIG_ENDIAN -> new BinaryCharReadValueFromStreamListener();
8157                 };
8158                 case PLY_UCHAR -> switch (storageMode) {
8159                     case PLY_ASCII -> new AsciiUcharReadValueFromStreamListener();
8160                     case PLY_LITTLE_ENDIAN, PLY_BIG_ENDIAN -> new BinaryUcharReadValueFromStreamListener();
8161                 };
8162                 case PLY_SHORT -> switch (storageMode) {
8163                     case PLY_ASCII -> new AsciiShortReadValueFromStreamListener();
8164                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianShortReadValueFromStreamListener();
8165                     case PLY_BIG_ENDIAN -> new BinaryBigEndianShortReadValueFromStreamListener();
8166                 };
8167                 case PLY_USHORT -> switch (storageMode) {
8168                     case PLY_ASCII -> new AsciiUshortReadValueFromStreamListener();
8169                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianUshortReadValueFromStreamListener();
8170                     case PLY_BIG_ENDIAN -> new BinaryBigEndianUshortReadValueFromStreamListener();
8171                 };
8172                 case PLY_INT -> switch (storageMode) {
8173                     case PLY_ASCII -> new AsciiIntReadValueFromStreamListener();
8174                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianIntReadValueFromStreamListener();
8175                     case PLY_BIG_ENDIAN -> new BinaryBigEndianIntReadValueFromStreamListener();
8176                 };
8177                 case PLY_UINT -> switch (storageMode) {
8178                     case PLY_ASCII -> new AsciiUintReadValueFromStreamListener();
8179                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianUintReadValueFromStreamListener();
8180                     case PLY_BIG_ENDIAN -> new BinaryBigEndianUintReadValueFromStreamListener();
8181                 };
8182                 case PLY_FLOAT -> switch (storageMode) {
8183                     case PLY_ASCII -> new AsciiFloatReadValueFromStreamListener();
8184                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianFloatReadValueFromStreamListener();
8185                     case PLY_BIG_ENDIAN -> new BinaryBigEndianFloatReadValueFromStreamListener();
8186                 };
8187                 case PLY_DOUBLE -> switch (storageMode) {
8188                     case PLY_ASCII -> new AsciiDoubleReadValueFromStreamListener();
8189                     case PLY_LITTLE_ENDIAN -> new BinaryLittleEndianDoubleReadValueFromStreamListener();
8190                     case PLY_BIG_ENDIAN -> new BinaryBigEndianDoubleReadValueFromStreamListener();
8191                 };
8192             };
8193         }
8194 
8195         /**
8196          * Sets the listener to read length value from temporal buffer to
8197          * provided property.
8198          *
8199          * @param property A PLY header property.
8200          * @throws NotAvailableException Raised if a listener cannot be set
8201          *                               for given property because its data type is not supported.
8202          */
8203         private void setReadLengthValueFromBufferListener(final PropertyPLY property) throws NotAvailableException {
8204             switch (property.getLengthType()) {
8205                 case PLY_INT8:
8206                     property.setReadLengthValueFromBufferListener(new FaceInt8ReadLengthValueFromBufferListener());
8207                     break;
8208                 case PLY_UINT8:
8209                     property.setReadLengthValueFromBufferListener(new FaceUint8ReadLengthValueFromBufferListener());
8210                     break;
8211                 case PLY_INT16:
8212                     property.setReadLengthValueFromBufferListener(new FaceInt16ReadLengthValueFromBufferListener());
8213                     break;
8214                 case PLY_UINT16:
8215                     property.setReadLengthValueFromBufferListener(new FaceUint16ReadLengthValueFromBufferListener());
8216                     break;
8217                 case PLY_INT32:
8218                     property.setReadLengthValueFromBufferListener(new FaceInt32ReadLengthValueFromBufferListener());
8219                     break;
8220                 case PLY_UINT32:
8221                     property.setReadLengthValueFromBufferListener(new FaceUint32ReadLengthValueFromBufferListener());
8222                     break;
8223                 case PLY_FLOAT32:
8224                     property.setReadLengthValueFromBufferListener(new FaceFloat32ReadLengthValueFromBufferListener());
8225                     break;
8226                 case PLY_FLOAT64:
8227                     property.setReadLengthValueFromBufferListener(new FaceFloat64ReadLengthValueFromBufferListener());
8228                     break;
8229                 case PLY_CHAR:
8230                     property.setReadLengthValueFromBufferListener(new FaceCharReadLengthValueFromBufferListener());
8231                     break;
8232                 case PLY_UCHAR:
8233                     property.setReadLengthValueFromBufferListener(new FaceUcharReadLengthValueFromBufferListener());
8234                     break;
8235                 case PLY_SHORT:
8236                     property.setReadLengthValueFromBufferListener(new FaceShortReadLengthValueFromBufferListener());
8237                     break;
8238                 case PLY_USHORT:
8239                     property.setReadLengthValueFromBufferListener(new FaceUshortReadLengthValueFromBufferListener());
8240                     break;
8241                 case PLY_INT:
8242                     property.setReadLengthValueFromBufferListener(new FaceIntReadLengthValueFromBufferListener());
8243                     break;
8244                 case PLY_UINT:
8245                     property.setReadLengthValueFromBufferListener(new FaceUintReadLengthValueFromBufferListener());
8246                     break;
8247                 case PLY_FLOAT:
8248                     property.setReadLengthValueFromBufferListener(new FaceFloatReadLengthValueFromBufferListener());
8249                     break;
8250                 case PLY_DOUBLE:
8251                     property.setReadLengthValueFromBufferListener(new FaceDoubleReadLengthValueFromBufferListener());
8252                     break;
8253                 default:
8254                     throw new NotAvailableException();
8255             }
8256         }
8257     }
8258 }
8259 
8260 //TODO: add cancel method
8261 //TODO: add unit tests for loader ply