View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.formats.psd;
18  
19  import java.io.IOException;
20  import java.io.PrintWriter;
21  import java.io.StringWriter;
22  import java.util.logging.Level;
23  import java.util.logging.Logger;
24  
25  public class PsdHeaderInfo {
26  
27      private static final Logger LOGGER = Logger.getLogger(PsdHeaderInfo.class.getName());
28  
29      public final int version;
30      private final byte[] reserved;
31      public final int channels;
32      public final int rows;
33      public final int columns;
34      public final int depth;
35      public final int mode;
36  
37      public PsdHeaderInfo(final int version, final byte[] reserved, final int channels, final int rows, final int columns, final int depth, final int mode) {
38          this.version = version;
39          this.reserved = reserved.clone();
40          this.channels = channels;
41          this.rows = rows;
42          this.columns = columns;
43          this.depth = depth;
44          this.mode = mode;
45  
46      }
47  
48      public void dump() {
49          try (StringWriter sw = new StringWriter();
50                  PrintWriter pw = new PrintWriter(sw)) {
51              dump(pw);
52              pw.flush();
53              sw.flush();
54              LOGGER.fine(sw.toString());
55          } catch (final IOException e) {
56              LOGGER.log(Level.SEVERE, e.getMessage(), e);
57          }
58      }
59  
60      public void dump(final PrintWriter pw) {
61          pw.println("");
62          pw.println("Header");
63          pw.println("Version: " + version + " (" + Integer.toHexString(version) + ")");
64          pw.println("Channels: " + channels + " (" + Integer.toHexString(channels) + ")");
65          pw.println("Rows: " + rows + " (" + Integer.toHexString(rows) + ")");
66          pw.println("Columns: " + columns + " (" + Integer.toHexString(columns) + ")");
67          pw.println("Depth: " + depth + " (" + Integer.toHexString(depth) + ")");
68          pw.println("Mode: " + mode + " (" + Integer.toHexString(mode) + ")");
69          pw.println("Reserved: " + reserved.length);
70          pw.println("");
71          pw.flush();
72      }
73  
74      public byte[] getReserved() {
75          return reserved.clone();
76      }
77  
78  }