View Javadoc
1   /*
2   Copyright (c) 2010 James Ahlborn
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  
17  package com.healthmarketscience.jackcess.impl;
18  
19  import java.io.IOException;
20  import java.nio.ByteBuffer;
21  
22  /**
23   * Interface for a handler which can encode/decode a specific access page
24   * encoding.
25   *
26   * @author James Ahlborn
27   */
28  public interface CodecHandler 
29  {
30    /**
31     * Returns {@code true} if this handler can encode partial pages,
32     * {@code false} otherwise.  If this method returns {@code false}, the
33     * {@link #encodePage} method will never be called with a non-zero
34     * pageOffset.
35     */
36    public boolean canEncodePartialPage();
37  
38    /**
39     * Returns {@code true} if this handler can decode a page inline,
40     * {@code false} otherwise.  If this method returns {@code false}, the
41     * {@link #decodePage} method will always be called with separate buffers.
42     */
43    public boolean canDecodeInline();
44  
45    /**
46     * Decodes the given page buffer.
47     *
48     * @param inPage the page to be decoded
49     * @param outPage the decoded page.  if {@link #canDecodeInline} is {@code
50     *                true}, this will be the same buffer as inPage.
51     * @param pageNumber the page number of the given page
52     * 
53     * @throws IOException if an exception occurs during decoding
54     */
55    public void decodePage(ByteBuffer inPage, ByteBuffer outPage, int pageNumber) 
56      throws IOException;
57  
58    /**
59     * Encodes the given page buffer into a new page buffer and returns it.  The
60     * returned page buffer will be used immediately and discarded so that it
61     * may be re-used for subsequent page encodings.
62     *
63     * @param page the page to be encoded, should not be modified
64     * @param pageNumber the page number of the given page
65     * @param pageOffset offset within the page at which to start writing the
66     *                   page data
67     * 
68     * @throws IOException  if an exception occurs during decoding
69     *
70     * @return the properly encoded page buffer for the given page buffer 
71     */
72    public ByteBuffer encodePage(ByteBuffer page, int pageNumber, 
73                                 int pageOffset) 
74      throws IOException;
75  }