Java Code Examples for java.io.RandomAccessFile#getFilePointer()
The following examples show how to use
java.io.RandomAccessFile#getFilePointer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lyrics3v2Field.java From openbd-core with GNU General Public License v3.0 | 6 votes |
public void read(final RandomAccessFile file) throws InvalidTagException, IOException { final byte[] buffer = new byte[6]; // lets scan for a non-zero byte; long filePointer; byte b; do { filePointer = file.getFilePointer(); b = file.readByte(); } while (b == 0); file.seek(filePointer); // read the 3 character ID file.read(buffer, 0, 3); final String identifier = new String(buffer, 0, 3); // is this a valid identifier? if (TagUtility.isLyrics3v2FieldIdentifier(identifier) == false) { throw new InvalidTagException(identifier + " is not a valid ID3v2.4 frame"); } this.setBody(readBody(identifier, file)); }
Example 2
Source File: Lyrics3v2.java From openbd-core with GNU General Public License v3.0 | 6 votes |
public void read(final RandomAccessFile file) throws TagNotFoundException, IOException { final long filePointer; final int lyricSize; if (seek(file)) { lyricSize = seekSize(file); } else { throw new TagNotFoundException("Lyrics3v2.00 Tag Not Found"); } // reset file pointer to the beginning of the tag; seek(file); filePointer = file.getFilePointer(); this.fieldMap = new HashMap(); Lyrics3v2Field lyric; // read each of the fields while ((file.getFilePointer() - filePointer) < (lyricSize - 11)) { try { lyric = new Lyrics3v2Field(file); setField(lyric); } catch (InvalidTagException ex) { // keep reading until we're done } } }
Example 3
Source File: PartFilesReassembly.java From p3-batchrefine with Apache License 2.0 | 6 votes |
private static long findClosingRDFBracket(RandomAccessFile file) throws IOException { long length = file.length(); file.seek((long) (length * 0.9)); long lastLinePosition = -1; String lastLine = ""; while (!lastLine.trim().equals("</rdf:RDF>")) { lastLinePosition = file.getFilePointer(); lastLine = file.readLine(); if (lastLine == null) throw new IOException( "Malformed RDF, last line is not an RDF closing bracket: " + lastLine); } return lastLinePosition; }
Example 4
Source File: AWXDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void readXY_3(Range yRange, Range xRange, IndexIterator ii) throws FileNotFoundException, IOException { RandomAccessFile br = new RandomAccessFile(this.getFileName(), "r"); //Read byte data br.seek(_lenRecord * _numHeadRecord); int length = (int) (br.length() - br.getFilePointer()); byte[] imageBytes = new byte[length]; br.read(imageBytes); br.close(); int i, j; int bi = 0; int value = 0; byte[] vbytes = new byte[_byteGridData]; float[] data = new float[_numLatGrid * _numLonGrid]; int idx; for (i = 0; i < _numLatGrid; i++) { for (j = 0; j < _numLonGrid; j++) { vbytes = Arrays.copyOfRange(imageBytes, bi, bi + _byteGridData); if (_byteGridData == 1) { value = DataConvert.byte2Int(vbytes[0]); } else if (_byteGridData == 2) { value = DataConvert.bytes2Int(vbytes, byteOrder); } else if (_byteGridData == 4) { value = DataConvert.bytes2Int(vbytes, byteOrder); } idx = (_numLatGrid - i - 1) * _numLonGrid + j; data[idx] = (float) (value + _baseData) / _scaleFactor; bi += _byteGridData; } } for (int y = yRange.first(); y <= yRange.last(); y += yRange.stride()) { for (int x = xRange.first(); x <= xRange.last(); x += xRange.stride()) { int index = y * _numLonGrid + x; ii.setFloatNext(data[index]); } } }
Example 5
Source File: PersistentMap.java From sc2gears with Apache License 2.0 | 5 votes |
/** * Creates a new PersistentMap. * @param rootFolder root folder to read/write files to * @param version tells the version of the data stored in the persistent map; if it does not equal to the version of the persistent file, it will be cleared automatically * @throws IOException if the persistent map could not be initialized */ public PersistentMap( final File rootFolder, final short version ) throws IOException { indexFile = new RandomAccessFile( new File( rootFolder, "index" ), "rw" ); if ( indexFile.getChannel().tryLock() == null ) throw new IOException( "Index file is already in use!" ); dataFile = new RandomAccessFile( new File( rootFolder, "data" ), "rw" ); if ( dataFile.getChannel().tryLock() == null ) throw new IOException( "Data file is already in use!" ); this.version = version; final long indexSize = indexFile.length(); if ( indexSize == 0 || indexFile.readShort() != version ) // New file or old version? clear(); else { // Read the index file into memory String key; ValueInfo valueInfo; while ( indexFile.getFilePointer() < indexSize ) { key = indexFile.readUTF(); valueInfo = new ValueInfo(); valueInfo.position = indexFile.readInt(); valueInfo.size = indexFile.readInt(); indexMap.put( key, valueInfo ); } } }
Example 6
Source File: RecordingInput.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void read(RandomAccessFile file, int amount) throws IOException { blockPosition = file.getFilePointer(); // reuse byte array, if possible if (amount != bytes.length) { bytes = new byte[amount]; } file.readFully(bytes); }
Example 7
Source File: MP3File.java From openbd-core with GNU General Public License v3.0 | 5 votes |
/** * Returns true if the first MP3 frame can be found for the MP3 file argument. It is recursive and called by * seekMP3Frame. This is the first byte of music data and not the ID3 Tag Frame. * * @param file MP3 file to seek * @param iterations recursive counter * * @return true if the first MP3 frame can be found * * @throws IOException on any I/O error */ private boolean seekNextMP3Frame(final RandomAccessFile file, final int iterations) throws IOException { final boolean syncFound; final byte[] buffer; final byte first; final byte second; final long filePointer; if (iterations == 0) { syncFound = true; } else { try { readFrameHeader(file); } catch (TagException ex) { return false; } final int size = getFrameSize(); if ((size <= 0) || (size > file.length())) { return false; } buffer = new byte[size - 4]; file.read(buffer); filePointer = file.getFilePointer(); first = file.readByte(); if (first == (byte) 0xFF) { second = (byte) (file.readByte() & (byte) 0xE0); if (second == (byte) 0xE0) { file.seek(filePointer); // recursively find the next frames syncFound = seekNextMP3Frame(file, iterations - 1); } else { syncFound = false; } } else { syncFound = false; } } return syncFound; }
Example 8
Source File: PersistentMap.java From scelight with Apache License 2.0 | 5 votes |
/** * Creates a new {@link PersistentMap}. * * @param rootFolder root folder to read/write files to * @param version tells the version of the data stored in the persistent map; if it does not equal to the version of the persistent file, it will be cleared * automatically * @throws IOException if the persistent map could not be initialized */ public PersistentMap( final Path rootFolder, final VersionBean version ) throws IOException { this.rootFolder = rootFolder; if ( !Files.exists( rootFolder ) ) Files.createDirectories( rootFolder ); final Path indexPath = rootFolder.resolve( "index" ); indexFile = new RandomAccessFile( indexPath.toFile(), "rw" ); if ( indexFile.getChannel().tryLock() == null ) throw new IOException( "Index file is already in use: " + indexPath ); final Path dataPath = rootFolder.resolve( "data" ); dataFile = new RandomAccessFile( dataPath.toFile(), "rw" ); if ( dataFile.getChannel().tryLock() == null ) throw new IOException( "Data file is already in use: " + dataPath ); this.version = version; final long indexSize = indexFile.length(); // New file or old version? final VersionBean oldVersion = indexSize == 0 ? null : VersionBean.fromString( indexFile.readUTF() ); if ( !version.equals( oldVersion ) ) { if ( oldVersion != null && Env.LOGGER.testTrace() ) Env.LOGGER.trace( "Persistent map content outdated (old version: " + oldVersion + ", new version: " + version + "): " + rootFolder ); clear(); } else { // Read the index file into memory String key; while ( indexFile.getFilePointer() < indexSize ) { key = indexFile.readUTF(); final int pos = indexFile.readInt(); final int size = indexFile.readInt(); indexMap.put( key, new ValueInfo( pos, size ) ); } if ( Env.LOGGER.testTrace() ) Env.LOGGER.trace( "Loaded " + indexMap.size() + " entries from persistent map: " + rootFolder ); } }
Example 9
Source File: ByteStore.java From COLA with GNU Lesser General Public License v2.1 | 5 votes |
private List<MockData> loadDataFileHead(RandomAccessFile rf) throws IOException { List<MockData> mockDataList = new ArrayList<>(); long fileLength = rf.length(); // 返回此文件中的当前偏移量 long start = rf.getFilePointer(); long readIndex = start + fileLength -1; String line; // 设置偏移量为文件末尾 rf.seek(readIndex); int c = -1; while (readIndex > start) { c = rf.read(); String readText = null; if (c == '\n' || c == '\r') { line = rf.readLine(); if (line != null) { readText = new String(line.getBytes("ISO-8859-1")); } if(StringUtils.isBlank(readText)){ continue; } if(Constants.RESPONSE_DATA_DELIMITER.equals(readText)){ break; }else{ MockData mockData = createMockDataHead(readText); mockDataList.add(mockData); } readIndex--; } readIndex--; rf.seek(readIndex); } return mockDataList; }
Example 10
Source File: ChunkSplit.java From p3-batchrefine with Apache License 2.0 | 5 votes |
private long findNextEOLPosition(RandomAccessFile seeakable, long blocksize) throws IOException, EndReachedException { if (seeakable.skipBytes((int) blocksize) < blocksize) throw new EndReachedException(); else seeakable.readLine(); return seeakable.getFilePointer(); }
Example 11
Source File: PartFilesReassembly.java From p3-batchrefine with Apache License 2.0 | 5 votes |
private static long findTurtlePrefixEnd(RandomAccessFile file) throws IOException { long lastLinePosition = -1; String line = ""; while ((line = file.readLine()) != null) { if (!line.trim().startsWith("@")) break; lastLinePosition = file.getFilePointer(); } return lastLinePosition; }
Example 12
Source File: ID3v2_2.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public void write(final RandomAccessFile file) throws IOException { final String str; ID3v2_2Frame frame; final Iterator iterator; final byte[] buffer = new byte[6]; final MP3File mp3 = new MP3File(); mp3.seekMP3Frame(file); final long mp3start = file.getFilePointer(); file.seek(0); // write the first 10 tag bytes str = "ID3"; for (int i = 0; i < str.length(); i++) { buffer[i] = (byte) str.charAt(i); } buffer[3] = 2; buffer[4] = 0; if (this.unsynchronization) { buffer[5] |= TagConstant.MASK_V22_UNSYNCHRONIZATION; } if (this.compression) { buffer[5] |= TagConstant.MASK_V22_COMPRESSION; } file.write(buffer); //write size; file.write(sizeToByteArray((int) mp3start - 10)); // write all frames iterator = this.getFrameIterator(); while (iterator.hasNext()) { frame = (ID3v2_2Frame) iterator.next(); frame.write(file); } }
Example 13
Source File: ARLDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public GridData getGridData_Level(int lonIdx, int latIdx, String varName, int timeIdx) { try { RandomAccessFile br = new RandomAccessFile(this.getFileName(), "r"); byte[] dataBytes; DataLabel aDL; int xNum, yNum, nvarIdx, levIdx, lNum; xNum = dataHead.NX; yNum = dataHead.NY; Variable var = this.getVariable(varName); lNum = var.getLevelNum(); double[][] gridData; double aValue; GridData aGridData = new GridData(); aGridData.missingValue = missingValue; aGridData.xArray = new double[lNum]; aGridData.yArray = new double[1]; aGridData.yArray[0] = 0; aGridData.data = new double[1][lNum]; br.seek(timeIdx * recsPerTime * recLen); br.seek(br.getFilePointer() + indexLen); long aLevPosition = br.getFilePointer(); //levIdx = this.getVariables().get(varIdx).getLevelIdxs().get(0); for (int i = 0; i < lNum; i++) { nvarIdx = var.getVarInLevelIdxs().get(i); levIdx = var.getLevelIdxs().get(i); br.seek(aLevPosition); for (int j = 0; j < levIdx; j++) { br.seek(br.getFilePointer() + LevelVarList.get(j).size() * recLen); } br.seek(br.getFilePointer() + nvarIdx * recLen); //Read label aDL = ARLDataInfo.readDataLabel(br); //Read Data dataBytes = new byte[(int)recLen - 50]; br.read(dataBytes); gridData = unpackARLGridData(dataBytes, xNum, yNum, aDL); aValue = gridData[latIdx][lonIdx]; aGridData.xArray[i] = levels.get(levIdx); aGridData.data[0][i] = aValue; } br.close(); return aGridData; } catch (IOException ex) { Logger.getLogger(ARLDataInfo.class.getName()).log(Level.SEVERE, null, ex); return null; } }
Example 14
Source File: ARLDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public GridData getGridData_LevelTime(int latIdx, String varName, int lonIdx) { try { int xNum, yNum, lNum, nvarIdx, levIdx, t, tNum; xNum = dataHead.NX; yNum = dataHead.NY; Variable var = this.getVariable(varName); lNum = var.getLevelNum(); tNum = this.getTimeNum(); double[][] theData; RandomAccessFile br = new RandomAccessFile(this.getFileName(), "r"); byte[] dataBytes; DataLabel aDL; double[][] newGridData = new double[lNum][tNum]; long aLevPosition; for (t = 0; t < tNum; t++) { br.seek(t * recsPerTime * recLen); br.seek(br.getFilePointer() + indexLen); aLevPosition = br.getFilePointer(); //levIdx = this.getVariables().get(varIdx).getLevelIdxs().get(0); for (int i = 0; i < lNum; i++) { nvarIdx = var.getVarInLevelIdxs().get(i); levIdx = var.getLevelIdxs().get(i); br.seek(aLevPosition); for (int j = 0; j < levIdx; j++) { br.seek(br.getFilePointer() + LevelVarList.get(j).size() * recLen); } br.seek(br.getFilePointer() + nvarIdx * recLen); //Read label aDL = ARLDataInfo.readDataLabel(br); //Read Data dataBytes = new byte[(int)recLen - 50]; br.read(dataBytes); theData = unpackARLGridData(dataBytes, xNum, yNum, aDL); newGridData[i][t] = theData[latIdx][lonIdx]; } } br.close(); GridData gridData = new GridData(); gridData.data = newGridData; gridData.missingValue = missingValue; gridData.xArray = new double[tNum]; for (int i = 0; i < tNum; i++) { gridData.xArray[i] = JDateUtil.toOADate(this.getTimes().get(i)); } gridData.yArray = new double[lNum]; for (int i = 0; i < lNum; i++) { gridData.yArray[i] = var.getLevels().get(i); } return gridData; } catch (IOException ex) { Logger.getLogger(ARLDataInfo.class.getName()).log(Level.SEVERE, null, ex); return null; } }
Example 15
Source File: TailServlet.java From document-management-system with GNU General Public License v2.0 | 4 votes |
/** * Do the magic */ private void tail(File file, PrintWriter out, int timeout) throws InterruptedException, IOException { long filePointer = 0; int toLeave = 0; int row = 0; out.println("<table class=\"results\" width=\"90%\">"); out.println("<tr><th>#</th><th>Line</th></tr>"); while (true) { long len = file.length(); if (len < filePointer) { // Log must have been shorted or deleted. out.print("<tr class=\"fuzzy\"><td colspan=\"2\" align=\"center\">"); out.print("<b>Log file was reset. Restarting logging from start of file.</b>"); out.println("</td></tr>"); out.flush(); filePointer = 0; row = 0; toLeave = 0; } else if (len > filePointer) { // File must have had something added to it! RandomAccessFile raf = new RandomAccessFile(file, "r"); raf.seek(filePointer); String line = null; while ((line = raf.readLine()) != null) { out.print("<tr class=\"" + (row++ % 2 == 0 ? "even" : "odd") + "\">"); out.print("<td>" + row + "</td><td>"); out.print(FormatUtil.escapeHtml(new String(line.getBytes("ISO-8859-1"), "UTF-8"))); out.println("</td></tr>"); out.flush(); } filePointer = raf.getFilePointer(); raf.close(); toLeave = 0; } else { if (toLeave++ > timeout) { break; } } Thread.sleep(1000); } out.print("<tr class=\"fuzzy\"><td colspan=\"2\" align=\"center\">"); out.print("<b>Log file was not modified for " + timeout + " seconds</b>"); out.println("</td></tr>"); out.println("</table>"); }
Example 16
Source File: Lyrics3v2.java From openbd-core with GNU General Public License v3.0 | 4 votes |
public void write(final RandomAccessFile file) throws IOException { int offset = 0; final long filePointer; final byte[] buffer = new byte[6 + 9]; String str; Lyrics3v2Field field; final Iterator iterator; ID3v1 id3v1tag = new ID3v1(); id3v1tag = id3v1tag.getID3tag(file); delete(file); file.seek(file.length()); filePointer = file.getFilePointer(); str = "LYRICSBEGIN"; for (int i = 0; i < str.length(); i++) { buffer[i] = (byte) str.charAt(i); } file.write(buffer, 0, str.length()); // IND needs to go first. lets create/update it and write it first. updateField("IND"); field = (Lyrics3v2Field) this.fieldMap.get("IND"); field.write(file); iterator = this.fieldMap.values().iterator(); while (iterator.hasNext()) { field = (Lyrics3v2Field) iterator.next(); final String id = field.getIdentifier(); final boolean save = TagOptionSingleton.getInstance().getLyrics3SaveField(id); if ((id.equals("IND") == false) && save) { field.write(file); } } final long size; size = file.getFilePointer() - filePointer; str = Long.toString(size); for (int i = 0; i < (6 - str.length()); i++) { buffer[i] = (byte) '0'; } offset += (6 - str.length()); for (int i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } offset += str.length(); str = "LYRICS200"; for (int i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } offset += str.length(); file.write(buffer, 0, offset); if (id3v1tag != null) { id3v1tag.write(file); } }
Example 17
Source File: ARLDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public GridData getGridData_LevelLon(int latIdx, String varName, int timeIdx) { try { int xNum, yNum, lNum, nvarIdx, levIdx; xNum = dataHead.NX; yNum = dataHead.NY; Variable var = this.getVariable(varName); lNum = var.getLevelNum(); double[][] theData; RandomAccessFile br = new RandomAccessFile(this.getFileName(), "r"); byte[] dataBytes; DataLabel aDL; double[][] newGridData = new double[lNum][xNum]; long aLevPosition; br.seek(timeIdx * recsPerTime * recLen); br.seek(br.getFilePointer() + indexLen); aLevPosition = br.getFilePointer(); //levIdx = Variables[cvarIdx].LevelIdxs[0]; for (int i = 0; i < lNum; i++) { nvarIdx = var.getVarInLevelIdxs().get(i); levIdx = var.getLevelIdxs().get(i); br.seek(aLevPosition); for (int j = 0; j < levIdx; j++) { br.seek(br.getFilePointer() + LevelVarList.get(j).size() * recLen); } br.seek(br.getFilePointer() + nvarIdx * recLen); //Read label aDL = ARLDataInfo.readDataLabel(br); //Read Data dataBytes = new byte[(int)recLen - 50]; br.read(dataBytes); theData = unpackARLGridData(dataBytes, xNum, yNum, aDL); for (int j = 0; j < xNum; j++) { newGridData[i][j] = theData[latIdx][j]; } } br.close(); GridData gridData = new GridData(); gridData.data = newGridData; gridData.missingValue = missingValue; gridData.xArray = X; gridData.yArray = new double[lNum]; for (int i = 0; i < lNum; i++) { gridData.yArray[i] = var.getLevels().get(i); } return gridData; } catch (IOException ex) { Logger.getLogger(ARLDataInfo.class.getName()).log(Level.SEVERE, null, ex); return null; } }
Example 18
Source File: PegasusSubmitDAG.java From pegasus with Apache License 2.0 | 4 votes |
/** * Modifies the dagman condor submit file for metrics reporting. * * @param file * @return true if file is modified, else false * @throws CodeGeneratorException */ protected boolean modifyDAGManSubmitFileForMetrics(File file) throws CodeGeneratorException { // modify the environment string to add the environment for // enabling DAGMan metrics if so required. Metrics metricsReporter = new Metrics(); metricsReporter.initialize(mBag); ENV env = metricsReporter.getDAGManMetricsEnv(); if (env.isEmpty()) { return false; } else { // we read the DAGMan submit file in and grab the environment from it // and add the environment key to the second last line with the // Pegasus metrics environment variables added. try { RandomAccessFile raf = new RandomAccessFile(file, "rw"); String dagmanEnvString = ""; String line = null; long previous = raf.getFilePointer(); while ((line = raf.readLine()) != null) { if (line.startsWith("environment")) { dagmanEnvString = line; } if (line.startsWith("queue")) { // backtrack to previous file position i.e just before queue raf.seek(previous); StringBuilder dagmanEnv = new StringBuilder(dagmanEnvString); if (dagmanEnvString.isEmpty()) { dagmanEnv.append("environment="); } else { dagmanEnv.append(";"); } for (Iterator it = env.getProfileKeyIterator(); it.hasNext(); ) { String key = (String) it.next(); dagmanEnv.append(key).append("=").append(env.get(key)).append(";"); } mLogger.log( "Updated environment for dagman is " + dagmanEnv.toString(), LogManager.DEBUG_MESSAGE_LEVEL); raf.writeBytes(dagmanEnv.toString()); raf.writeBytes(System.getProperty("line.separator", "\r\n")); raf.writeBytes("queue"); break; } previous = raf.getFilePointer(); } raf.close(); } catch (IOException e) { throw new CodeGeneratorException( "Error while reading dagman .condor.sub file " + file, e); } } return true; }
Example 19
Source File: GrADSDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public GridData getGridData_Level(int lonIdx, int latIdx, String varName, int timeIdx) { try { int varIdx = this.getVariableIndex(varName); String filePath = DSET; int tIdx = timeIdx; if (OPTIONS.template) { Object[] result = getFilePath_Template(timeIdx); filePath = (String) result[0]; tIdx = (int) result[1]; } RandomAccessFile br = new RandomAccessFile(filePath, "r"); int i, lNum; byte[] aBytes = new byte[4]; float aValue; GridData aGridData = new GridData(); aGridData.missingValue = this.getMissingValue(); aGridData.xArray = new double[ZDEF.ZNum]; aGridData.yArray = new double[1]; aGridData.yArray[0] = 0; aGridData.data = new double[1][ZDEF.ZNum]; br.seek(FILEHEADER + tIdx * RecLenPerTime); for (i = 0; i < varIdx; i++) { lNum = VARDEF.getVars().get(i).getLevelNum(); if (lNum == 0) { lNum = 1; } br.seek(br.getFilePointer() + lNum * RecordLen); } long aPosition = br.getFilePointer(); for (i = 0; i < ZDEF.ZNum; i++) { br.seek(aPosition + i * RecordLen); if (OPTIONS.sequential) { br.seek(br.getFilePointer() + 4); } br.seek(br.getFilePointer() + latIdx * XNum * 4 + lonIdx * 4); br.read(aBytes); aValue = DataConvert.bytes2Float(aBytes, _byteOrder); aGridData.xArray[i] = ZDEF.ZLevels[i]; aGridData.data[0][i] = aValue; } br.close(); return aGridData; } catch (IOException ex) { Logger.getLogger(GrADSDataInfo.class.getName()).log(Level.SEVERE, null, ex); } return null; }
Example 20
Source File: TTFParser.java From Android_Skin_2.0 with Apache License 2.0 | 4 votes |
private void parseInner(RandomAccessFile randomAccessFile) throws IOException { int majorVersion = randomAccessFile.readShort(); int minorVersion = randomAccessFile.readShort(); int numOfTables = randomAccessFile.readShort(); if (majorVersion != 1 || minorVersion != 0) { return; } // jump to TableDirectory struct randomAccessFile.seek(12); boolean found = false; byte[] buff = new byte[4]; TableDirectory tableDirectory = new TableDirectory(); for (int i = 0; i < numOfTables; i++) { randomAccessFile.read(buff); tableDirectory.name = new String(buff); tableDirectory.checkSum = randomAccessFile.readInt(); tableDirectory.offset = randomAccessFile.readInt(); tableDirectory.length = randomAccessFile.readInt(); if ("name".equalsIgnoreCase(tableDirectory.name)) { found = true; break; } else if (tableDirectory.name == null || tableDirectory.name.length() == 0) { break; } } // not found table of name if (!found) { return; } randomAccessFile.seek(tableDirectory.offset); NameTableHeader nameTableHeader = new NameTableHeader(); nameTableHeader.fSelector = randomAccessFile.readShort(); nameTableHeader.nRCount = randomAccessFile.readShort(); nameTableHeader.storageOffset = randomAccessFile.readShort(); NameRecord nameRecord = new NameRecord(); for (int i = 0; i < nameTableHeader.nRCount; i++) { nameRecord.platformID = randomAccessFile.readShort(); nameRecord.encodingID = randomAccessFile.readShort(); nameRecord.languageID = randomAccessFile.readShort(); nameRecord.nameID = randomAccessFile.readShort(); nameRecord.stringLength = randomAccessFile.readShort(); nameRecord.stringOffset = randomAccessFile.readShort(); long pos = randomAccessFile.getFilePointer(); byte[] bf = new byte[nameRecord.stringLength]; long vpos = tableDirectory.offset + nameRecord.stringOffset + nameTableHeader.storageOffset; randomAccessFile.seek(vpos); randomAccessFile.read(bf); String temp = new String(bf, "utf-16");//new String(bf, Charset.forName("utf-16")); fontProperties.put(nameRecord.nameID, temp); randomAccessFile.seek(pos); } }