View Javadoc

1   package org.csc.phynixx.common.io;
2   
3   /*
4    * #%L
5    * phynixx-common
6    * %%
7    * Copyright (C) 2014 Christoph Schmidt-Casdorff
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  
24  import java.io.IOException;
25  import java.util.ArrayList;
26  import java.util.Collections;
27  import java.util.List;
28  
29  /**
30   * Created by Christoph Schmidt-Casdorff on 13.01.14.
31   */
32  public class LogRecordPageWriter {
33  
34      private static final byte[][] EMPTY_DATA = new byte[][]{};
35  
36      private final List<LogRecordWriter> logWriters = new ArrayList<LogRecordWriter>();
37  
38      /**
39       * @return number of lines
40       */
41      public int size() {
42          return logWriters.size();
43      }
44  
45      public List<LogRecordWriter> getLogWriters() {
46          return Collections.unmodifiableList(this.logWriters);
47      }
48  
49      public LogRecordWriter newLine() {
50          LogRecordWriter logRecordWriter = new LogRecordWriter();
51          logWriters.add(logRecordWriter);
52          return (logRecordWriter);
53      }
54  
55  
56      public byte[][] toByteByte() throws IOException {
57          if (this.logWriters.isEmpty()) {
58              return EMPTY_DATA;
59          }
60  
61          byte[][] records = new byte[logWriters.size()][];
62  
63          for (int i = 0; i < logWriters.size(); i++) {
64              records[i] = logWriters.get(i).toByteArray();
65          }
66          return records;
67  
68      }
69  
70  
71  }