📄 vcx.java
字号:
// VCX: Model VCX files
// $Id: VCX.java,v 1.4 2003/07/24 20:48:28 cgm8 Exp $
/*
* Copyright (c) 1999 Carlos G Mendioroz.
*
* This file is part of D4J.
*
* D4J is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* D4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Report problems and direct all questions to:
*
* tron@acm.org
*/
package local.dialogic;
import java.io.*;
import java.util.*;
public class VCX extends java.lang.Object
{
protected FileInputStream vcxFile = null;
protected int fd;
protected int offset[];
protected int length[];
protected int rate;
protected int maxdir;
public VCX(String vcxFilename) throws IOException {
fd = Dialogic.openFile(vcxFilename, 0);
if (fd < 0)
throw new IOException("VCX(): Can not open file");
vcxFile = new FileInputStream(vcxFilename);
// Do not close vcxFile when closing vcx...
DataInputStream vcx = new DataInputStream(
new FileInputStream(vcxFilename));
maxdir = swap32(vcx.readInt());
rate = swap32(vcx.readInt());
vcx.readInt(); // Entries
vcx.readInt(); // zero1
vcx.readInt(); // size
vcx.readInt(); // zero2
offset = new int[maxdir+1];
length = new int[maxdir+1];
for (int i = 1; i <= maxdir; i++) {
offset[i] = swap32(vcx.readInt());
length[i] = swap32(vcx.readInt());
vcx.readInt(); // Annotation offset (asciiz)
}
vcx.close();
}
private int swap32(int val) {
return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val & 0xff0000) >> 8) | ((val & 0xff000000) >>> 24);
}
public void finalize() throws Throwable
{
close();
super.finalize();
}
public void close() {
if (vcxFile != null) {
try {
vcxFile.close();
} catch(IOException ioe) {}
vcxFile = null;
Dialogic.closeFile(fd);
fd = -1;
}
}
public IOTT iott(int index) {
if (index > maxdir || index <= 0)
return null;
IOTT io;
try {
io = new IOTT(fd, offset[index], length[index]);
} catch (IOException ioe) {
throw new RuntimeException ("Invalid VCX.iott(int)");
}
return io;
}
public IOTT iott(int index[]) {
IOTT io = new IOTT();
for (int i = 0; i < index.length; i++) {
if (index[i] > maxdir || index[i] <= 0)
return io;
try {
io.add(fd, offset[index[i]], length[index[i]]);
} catch (IOException ioe) {
throw new RuntimeException ("Invalid VCX.iott(int[])");
}
}
return io;
}
public IOTT iott(Vector index) {
IOTT io = new IOTT();
int e;
for (int i = 0; i < index.size(); i++) {
e = ((Integer)index.elementAt(i)).intValue();
if (e > maxdir || e <= 0)
return null;
try {
io.add(fd, offset[e], length[e]);
} catch (IOException ioe) {
throw new RuntimeException ("Invalid VCX.iott(Vector)");
}
}
return io;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -