/** * Let all editors save their content to a byte array and write it to a file. * * @param data */ private void writeToEepromFile() { byte[] eeprom = new byte[1024]; // assume size of 1024 bytes first and truncate later int offset = 0; for (Block b : blocks) { if (b.isVisible()) { int bitsProcessed = b.writeToEepromArray(eeprom, offset); offset += bitsProcessed; } } // cut size to 512 or 1024 bytes automatically if (offset <= 512 * 8) { byte[] eeprom2 = new byte[512]; System.arraycopy(eeprom, 0, eeprom2, 0, 512); eeprom = eeprom2; } try { Util.writeFile(filename, eeprom); } catch (IOException e) { JOptionPane.showMessageDialog( SHCEEMain.mySHCEEMain, "Could not write file " + filename + ".", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }