All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mcgath.jhove.module.png.ItxtChunk Maven / Gradle / Ivy

package com.mcgath.jhove.module.png;

import edu.harvard.hul.ois.jhove.ErrorMessage;
import edu.harvard.hul.ois.jhove.RepInfo;

/** Representation of the iTXt (internationalized text) chunk */
public class ItxtChunk extends GeneralTextChunk {

	/** Constructor */
	public ItxtChunk(int sig, long leng) {
		chunkType = sig;
		length = leng;
		ancillary = true;
		duplicateAllowed = true;
	}
	
	/** Process the data portion of the chunk. */
	public void processChunk(RepInfo info) throws Exception {
		final String badchunk = "Bad iTXt chunk";
		processChunkCommon(info);
		
		//iTXt chunks may have either compressed or uncompressed values.
		
		// state values:
		// 0 = getting keyword,
		// 1 = compression flag
		// 2 = compression type
		// 3 = language
		// 4 = translated keyword
		// 5 = value
		int state = 0;
		int compressionFlag = 0;
		int compressionType = 0;
		String keyword = null;
		String translatedKeyword = null;
		String language = null;
		byte[] valueData = null;
		StringBuilder sb = new StringBuilder();
		int valueIdx = 0;
		for (int i = 0; i  0) {
						language = sb.toString();
					}
					state = 4;
					sb = new StringBuilder();	// set up for translated keyword
				}
				break;
			case 4:		// translated keyword
				if (c == 0) {
					if (sb.length() > 0) {
						translatedKeyword = sb.toString();
					}
					state = 5;
					valueData = new byte[(int) length - i];	// set up for value
				}
				break;
			case 5:		// value
			default:
				valueData[valueIdx++] = (byte) c;
				break;
			}
			
			// assemble value, decompressing if necessary
			String value;
			if (compressionFlag != 0) {
				value = inflateToText(valueData);
			} else {
				value = new String (valueData, "ISO-8859-1");
			}
			_module.addKeyword(keyword, translatedKeyword, value,language);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy