Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.LinkedList;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class testClass
- {
- public long[] EDC_crctable;//call proper method here
- public long[][] L2sq;
- private int[] sector;
- public testClass()
- {
- EDC_crctable = genEDCcrctable();
- L2sq = genL2sq();
- //printData();
- //private int crc32(File file, long sectorOffset, int expectedNumOfBytes)
- System.out.println("" + crc32(new File("sagafrontier.iso"), 0, 2352));
- //^output of 1449755743
- }
- public static void main(String[] args)
- {
- testClass t = new testClass();
- }
- public long[] genEDCcrctable()
- {
- LinkedList<Long> tempList = new LinkedList<Long>();
- long[] tempArray = null;
- BufferedReader br = null;
- try
- {
- br = new BufferedReader(new FileReader(new File("EDC_crctable.txt")));
- String line = br.readLine();
- while (line != null)
- {
- tempList.add(Long.decode(line));
- line = br.readLine();
- }
- tempArray = new long[(tempList.size())];
- int counter = 0;
- for (Long curr : tempList)
- {
- tempArray[counter] = (long)curr;
- counter ++;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- if (br != null)
- {
- try
- {
- br.close();
- }
- catch (Exception e) {}
- }
- return tempArray;
- }
- }
- public long[][] genL2sq()
- {
- LinkedList<Long[]> tempList = new LinkedList<Long[]>();
- long[][] tempArray = null;
- BufferedReader br = null;
- try
- {
- br = new BufferedReader(new FileReader(new File("L2sq.txt")));
- String line = br.readLine();
- int columnLength = line.split(",").length;
- int rowLength = 0;
- while (line != null)
- {
- String[] lineStringArray = line.split(",");
- Long[] lineLongArray = new Long[lineStringArray.length];
- int i = 0;
- for (String part : lineStringArray)
- {
- lineLongArray[i] = Long.decode(lineStringArray[i]);
- i ++;
- }
- tempList.add(lineLongArray);
- line = br.readLine();
- rowLength ++;
- }
- tempArray = new long[rowLength][columnLength];
- for (int rowCounter = 0; rowCounter < rowLength; rowCounter ++)
- {
- for (int columnCounter = 0; columnCounter < columnLength; columnCounter ++)
- {
- if (columnCounter == 0)
- {
- System.out.print("");
- }
- tempArray[rowCounter][columnCounter] = tempList.get(rowCounter)[columnCounter];
- }
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- if (br != null)
- {
- try
- {
- br.close();
- }
- catch (Exception e) {}
- }
- return tempArray;
- }
- }
- //private int crc32(int[] sctr)
- private int crc32(File file, long sectorOffset, int expectedNumOfBytes)
- {
- RandomAccessFile raf = null;
- int returnVal = 0;
- try
- {
- raf = new RandomAccessFile(file, "r");
- raf.seek(sectorOffset * 2352);//need to account for location in sector
- byte[] sector = new byte[expectedNumOfBytes];
- for (int totalBytesRead=0, offset=0; totalBytesRead < expectedNumOfBytes; )
- {
- int numberOfBytesRemaining = expectedNumOfBytes - totalBytesRead;
- int bytesRead = raf.read(sector, offset, numberOfBytesRemaining);
- if (bytesRead == -1)
- {
- throw new IOException("The expected number of bytes wasn't found for " + file);
- }
- totalBytesRead += bytesRead;
- offset += bytesRead;
- }
- //byte[] sector = raf.read
- //^look up how you did read(byte[]) in snakeoil
- //int expectedNumberOfBytes = entrySize;
- //byte[] byteBuffer = new byte[expectedNumberOfBytes];
- //for (int totalBytesRead=0, offset=0; totalBytesRead < expectedNumberOfBytes; ) {
- // int numberOfBytesRemaining = expectedNumberOfBytes - totalBytesRead;
- // int bytesRead = zis.read(byteBuffer, offset, numberOfBytesRemaining);
- // if (bytesRead == -1) {
- // throw new IOException("The expected number of bytes was not found for: " + zipEntry.getName());
- // }
- // totalBytesRead += bytesRead;
- // offset += bytesRead;
- //
- //test above to see if it works after you write the rest of it.
- for (int i = 0; i < sector.length; i++)
- {
- //not sure if long or int, check later
- returnVal = ((int)EDC_crctable[(returnVal ^ sector[i]) & 0xFF] ^ (returnVal >> 8));
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- if (raf != null)
- {
- try
- {
- raf.close();
- return returnVal;
- }
- catch (Exception e) {}
- }
- }
- return returnVal;
- }
- public void printData()
- {
- int c = 0;
- for (long i : EDC_crctable)
- {
- System.out.println(c + ":\t" + i + "");
- c ++;
- }
- for (long[] arr : L2sq)
- {
- for (long i : arr)
- {
- System.out.print(i + ",");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement