📄 makelicense.java
字号:
outputStream.writeInt (pageTemplateLimit); // write the user limit to the string addJunkBytes (outputStream, random); outputStream.writeInt (userLimit); // write the site limit to the string addJunkBytes (outputStream, random); outputStream.writeInt (siteLimit); // write the license id to the string addJunkBytes (outputStream, random); byte[] stringAsBytes = licenseID.getBytes(CHAR_ENC); outputStream.writeInt (stringAsBytes.length); outputStream.write(stringAsBytes); // write the build number addJunkBytes (outputStream, random); outputStream.writeInt (buildNumber); // write the release number addJunkBytes (outputStream, random); outputStream.writeDouble (releaseNumber); // add the some junk bytes addJunkBytes (outputStream, random); bytes = byteStream.toByteArray(); outputStream = null; byteStream = null; } catch (IOException ex) { System.out.println ("ERROR : I/O error while writing to byte stream."); return; } // compute the stream CRC CRC32 crc = new CRC32(); crc.update (bytes); long checksum = crc.getValue (); //DisplayBytes (bytes); System.out.println (" stream size = "+bytes.length); System.out.println (" checksum = "+Long.toHexString (checksum)); // create the raw byte stream try { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream (byteStream); // add the CRC into the stream at a random position int offset = random.nextInt (bytes.length); outputStream.writeShort (offset); // write the first part of the original byte stream outputStream.write (bytes, 0, offset); // write the CRC outputStream.writeLong (checksum); // Write the remaining part of the original byte stream. outputStream.write (bytes, offset, bytes.length-offset); bytes = null; bytes = byteStream.toByteArray(); outputStream = null; byteStream = null; } catch (IOException ex) { System.out.println ("ERROR : I/O error while writing to byte stream."); return; } //DisplayBytes (bytes); System.out.println (" stream size = "+bytes.length); // write the stream to the file. try { // try to create the license file FileOutputStream fstream = new FileOutputStream (fileName); fstream.write (bytes); // flush the stream into the file and close the file fstream.flush(); fstream.close(); } catch (FileNotFoundException ex) { System.out.println ("ERROR : Could not create the license file"); return; } catch (SecurityException ex) { System.out.println ("ERROR : No security permissions to create the file."); return; } catch (IOException ex) { System.out.println ("ERROR : I/O error."); return; } System.out.println ("License successfully created.\n"); } //------------------------------------------------------------------------- private static void addJunkBytes (DataOutputStream stream, Random random) throws IOException { int amount = random.nextInt (200); // add between 0-199 junk bytes // add one to avoid 0 junk bytes. amount++; // add the offset in the stream stream.writeInt (amount); // add the junk bytes in the stream for (int i=0; i<amount; i++) { stream.writeByte (random.nextInt (255)); } } //------------------------------------------------------------------------- private static void DisplayHelp () { StringBuffer buffer = new StringBuffer (); buffer.append (" usage : MakeLicense [options]\n\n"); buffer.append (" options :\n"); buffer.append (" "+LICENSE_TYPE_OPTION+"\n"+ " license type (default="+ LICENSE_TYPE_OPTION_DEFAULT+") 1=Free Jahia, 2=ProJahia, rest currently undefined\n"); buffer.append (" "+PAGE_LIMIT_OPTION+"\n"+ " maximum number of custom pages (default="+ PAGE_LIMIT_OPTION_DEFAULT+"), use -1 to deactivate check \n"); buffer.append (" "+PAGE_TEMPLATE_LIMIT_OPTION+"\n"+ " maximum number of custom page templates (default="+ PAGE_TEMPLATE_LIMIT_OPTION_DEFAULT+"), use -1 to deactivate check\n"); buffer.append (" "+USER_LIMIT_OPTION+"\n"+ " maximum number of users (default="+ USER_LIMIT_OPTION_DEFAULT+"), use -1 to deactivate check\n"); buffer.append (" "+SITE_LIMIT_OPTION+"\n"+ " maximum number of sites (default="+ SITE_LIMIT_OPTION_DEFAULT+"), use -1 to deactivate check\n"); buffer.append (" "+LICENSE_ID_OPTION+"\n"+ " license id (default="+ LICENSE_ID_OPTION_DEFAULT+") usually IP address or hostname, -1 to deactivate check\n"); buffer.append (" "+BUILD_OPTION+"\n"+ " build number (default="+ BUILD_OPTION_DEFAULT +"), use -1 to deactivate check\n"); buffer.append (" "+RELEASE_NUMBER_OPTION+"\n"+ " release number (default="+ RELEASE_NUMBER_DEFAULT +"), use -1 to deactivate check\n"); buffer.append (" "+FILENAME_OPTION+"\n"+ " release number (default="+ LICENSE_DEFAULT_FILENAME +")\n"); buffer.append ("\n\n"); System.out.println (buffer.toString()); } //------------------------------------------------------------------------- private static void DisplayBytes (byte[] bytes) { System.out.print (" stream = "); for (int i=0; i<bytes.length; i++) { System.out.print (bytes[i]+" "); } System.out.print("\n"); } //------------------------------------------------------------------------- private static int parseInteger (String option, String argument) { int item = 0; try { item = Integer.parseInt (argument); if ((item < 0) && (item != -1)) { System.out.println (argument + " is an invalid value for option [" + option + "]"); System.exit(0); } } catch (NumberFormatException ex) { System.out.println ("Error: option "+ option + " has not a valid integer value!"); System.exit(0); } return item; } //------------------------------------------------------------------------- private static double parseDouble (String option, String argument) { double item = 0; try { item = Double.parseDouble (argument); if ((item < 0.0) && (item != -1.0)) { System.out.println (argument + " is an invalid value for option [" + option + "]"); System.exit(0); } } catch (NumberFormatException ex) { System.out.println ("Error: option "+ option + " has not a valid float value!"); System.exit(0); } return item; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -