| 1 | /* |
| 2 | * Copyright 2002-2019 Drew Noakes and contributors |
| 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 | * More information about this project is available at: |
| 17 | * |
| 18 | * https://drewnoakes.com/code/exif/ |
| 19 | * https://github.com/drewnoakes/metadata-extractor |
| 20 | */ |
| 21 | package com.drew.imaging.riff; |
| 22 | |
| 23 | import com.drew.lang.annotations.NotNull; |
| 24 | |
| 25 | /** |
| 26 | * Interface of an class capable of handling events raised during the reading of a RIFF file |
| 27 | * via {@link RiffReader}. |
| 28 | * |
| 29 | * @author Drew Noakes https://drewnoakes.com |
| 30 | */ |
| 31 | public interface RiffHandler |
| 32 | { |
| 33 | /** |
| 34 | * Gets whether the specified RIFF identifier is of interest to this handler. |
| 35 | * Returning <code>false</code> causes processing to stop after reading only |
| 36 | * the first twelve bytes of data. |
| 37 | * |
| 38 | * @param identifier The four character code identifying the type of RIFF data |
| 39 | * @return true if processing should continue, otherwise false |
| 40 | */ |
| 41 | boolean shouldAcceptRiffIdentifier(@NotNull String identifier); |
| 42 | |
| 43 | /** |
| 44 | * Gets whether this handler is interested in the specific chunk type. |
| 45 | * Returns <code>true</code> if the data should be copied into an array and passed |
| 46 | * to {@link RiffHandler#processChunk(String, byte[])}, or <code>false</code> to avoid |
| 47 | * the copy and skip to the next chunk in the file, if any. |
| 48 | * |
| 49 | * @param fourCC the four character code of this chunk |
| 50 | * @return true if {@link RiffHandler#processChunk(String, byte[])} should be called, otherwise false |
| 51 | */ |
| 52 | boolean shouldAcceptChunk(@NotNull String fourCC); |
| 53 | |
| 54 | /** |
| 55 | * Gets whether this handler is interested in the specific list type. |
| 56 | * Returns <code>true</code> if the chunks should continue being processed, |
| 57 | * or <code>false</code> to avoid any unknown chunks within the list. |
| 58 | * |
| 59 | * @param fourCC the four character code of this chunk |
| 60 | * @return true if {@link RiffHandler#processChunk(String, byte[])} should be called, otherwise false |
| 61 | */ |
| 62 | boolean shouldAcceptList(@NotNull String fourCC); |
| 63 | |
| 64 | /** |
| 65 | * Perform whatever processing is necessary for the type of chunk with its |
| 66 | * payload. |
| 67 | * |
| 68 | * This is only called if a previous call to {@link RiffHandler#shouldAcceptChunk(String)} |
| 69 | * with the same <code>fourCC</code> returned <code>true</code>. |
| 70 | * |
| 71 | * @param fourCC the four character code of the chunk |
| 72 | * @param payload they payload of the chunk as a byte array |
| 73 | */ |
| 74 | void processChunk(@NotNull String fourCC, @NotNull byte[] payload); |
| 75 | |
| 76 | /** |
| 77 | * Registers an error message for consumption after extraction. |
| 78 | * @param message the error message |
| 79 | */ |
| 80 | void addError(@NotNull String message); |
| 81 | } |