1 /*
2 Copyright (c) 2010 James Ahlborn
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA
18 */
19
20 package com.healthmarketscience.jackcess;
21
22 import java.io.IOException;
23 import java.nio.ByteBuffer;
24
25 /**
26 * Interface for a handler which can encode/decode a specific access page
27 * encoding.
28 *
29 * @author James Ahlborn
30 */
31 public interface CodecHandler
32 {
33 /**
34 * Returns {@code true} if this handler can encode partial pages,
35 * {@code false} otherwise. If this method returns {@code false}, the
36 * {@link #encodePage} method will never be called with a non-zero
37 * pageOffset.
38 */
39 public boolean canEncodePartialPage();
40
41 /**
42 * Decodes the given page buffer inline.
43 *
44 * @param page the page to be decoded
45 * @param pageNumber the page number of the given page
46 *
47 * @throws IOException if an exception occurs during decoding
48 */
49 public void decodePage(ByteBuffer page, int pageNumber) throws IOException;
50
51 /**
52 * Encodes the given page buffer into a new page buffer and returns it. The
53 * returned page buffer will be used immediately and discarded so that it
54 * may be re-used for subsequent page encodings.
55 *
56 * @param page the page to be encoded, should not be modified
57 * @param pageNumber the page number of the given page
58 * @param pageOffset offset within the page at which to start writing the
59 * page data
60 *
61 * @throws IOException if an exception occurs during decoding
62 *
63 * @return the properly encoded page buffer for the given page buffer
64 */
65 public ByteBuffer encodePage(ByteBuffer page, int pageNumber,
66 int pageOffset)
67 throws IOException;
68 }