Currently in my Java Project, the item bonuses are stored in a buffered file and read like this:
private static final void loadPackedBonuses() { try { RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r"); FileChannel channel = in.getChannel(); ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size()); itemBonuses = new HashMap<Integer, int[]>(buffer.remaining() / 38); while (buffer.hasRemaining()) { int itemId = buffer.getShort() & 0xffff; int[] bonuses = new int[18]; for (int index = 0; index < bonuses.length; index++) bonuses[index] = buffer.getShort(); itemBonuses.put(itemId, bonuses); } channel.close(); in.close(); } catch (Throwable e) { Logger.handle(e); } }
Now, I unpacked that into a .txt file and I'm stuck on writing what I unpacked back into a buffered file. The part that I'm stuck on is writing the array of bonuses. Here's what an item bonus line looks like:
16183 - -4 -4 167 -4 0 0 0 0 -1 1 0 0 0 0 160 0 0 0
Here's my code so far:
private static final void loadUnpackedBonuses() { try { DataOutputStream out = new DataOutputStream(new FileOutputStream( PACKED_PATH)); BufferedReader in = new BufferedReader( new FileReader("data/items/itembonuses.txt")); String line; while ((line = in.readLine()) != null) { String[] data = line.split(" - "); if (data == null) continue; int item = Integer.parseInt(data[0]); int[] bonuses = new int[18]; out.writeShort(item); for (int i = 0; i < bonuses.length; i++) { out.writeShort(bonuses[i]); } } in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
All and any help is appreciated.