doctheme: add LibreOffice theme file to LO share folder
[LibreOffice.git] / connectivity / com / sun / star / sdbcx / comp / hsqldb / StorageAccess.java
blob6a53d110e661fb09e0401e314da6e1d90f726240
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.sdbcx.comp.hsqldb;
21 @SuppressWarnings("ucd")
22 public class StorageAccess implements org.hsqldb.lib.Storage {
23 String key;
24 String name;
25 boolean readonly;
26 NativeStorageAccess access;
27 /** Creates a new instance of StorageAccess */
28 public StorageAccess(String name,Boolean readonly,Object key) throws java.io.IOException{
29 this.key = (String)key;
30 this.name = name;
31 this.readonly = readonly.booleanValue();
32 try {
33 access = new NativeStorageAccess(name,
34 this.readonly ? "r" : "rw"
35 ,key);
36 } catch(Exception ex1){
37 java.io.IOException ex2 = new java.io.IOException();
38 ex2.initCause(ex1);
39 throw ex2;
42 public void close() throws java.io.IOException{
43 access.close(name,key);
46 public long getFilePointer() throws java.io.IOException{
47 return access.getFilePointer(name,key);
50 public long length() throws java.io.IOException{
51 return access.length(name,key);
54 public int read() throws java.io.IOException{
55 return access.read(name,key);
58 public void read(byte[] b, int off, int len) throws java.io.IOException{
59 access.read(name,key,b,off,len);
62 // based on the same code that reads an int from the .data file in HSQLDB
63 public int readInt() throws java.io.IOException{
64 byte [] tmp = new byte [4];
66 int count = access.read(name,key,tmp,0, 4);
68 if (count != 4){
69 throw new java.io.IOException();
72 count = 0;
73 int ch0 = tmp[count++] & 0xff;
74 int ch1 = tmp[count++] & 0xff;
75 int ch2 = tmp[count++] & 0xff;
76 int ch3 = tmp[count] & 0xff;
78 return ((ch0 << 24) + (ch1 << 16) + (ch2 << 8) + (ch3));
81 public void seek(long position) throws java.io.IOException{
82 access.seek(name,key,position);
85 public void write(byte[] b, int offset, int length) throws java.io.IOException{
86 access.write(name,key,b,offset,length);
89 public void writeInt(int v) throws java.io.IOException{
90 byte [] oneByte = new byte [4];
91 oneByte[0] = (byte) ((v >>> 24) & 0xFF);
92 oneByte[1] = (byte) ((v >>> 16) & 0xFF);
93 oneByte[2] = (byte) ((v >>> 8) & 0xFF);
94 oneByte[3] = (byte) ((v >>> 0) & 0xFF);
96 write(oneByte,0,4);
99 public boolean isReadOnly() {
100 return readonly;
103 @SuppressWarnings("cast")
104 public long readLong() throws java.io.IOException {
105 return (((long) readInt()) << 32) + (((long) readInt()) & 0xFFFFFFFFL);
108 public boolean wasNio() {
109 return false;
112 public void writeLong(long v) throws java.io.IOException {
113 byte [] oneByte = new byte [8];
115 oneByte[0] = (byte) ((v >>> 56) & 0xFF);
116 oneByte[1] = (byte) ((v >>> 48) & 0xFF);
117 oneByte[2] = (byte) ((v >>> 40) & 0xFF);
118 oneByte[3] = (byte) ((v >>> 32) & 0xFF);
119 oneByte[4] = (byte) ((v >>> 24) & 0xFF);
120 oneByte[5] = (byte) ((v >>> 16) & 0xFF);
121 oneByte[6] = (byte) ((v >>> 8) & 0xFF);
122 oneByte[7] = (byte) ((v >>> 0) & 0xFF);
124 write(oneByte,0,8);