예제 #1
0
  /**
   * Reads a base class overrride from a resource file
   *
   * @param binaryClassName
   * @param fileName
   */
  private void registerBaseClassOverride(String binaryClassName, String fileName) {
    try {
      Method mDefineClass =
          ClassLoader.class.getDeclaredMethod(
              "defineClass", String.class, byte[].class, int.class, int.class);
      mDefineClass.setAccessible(true);

      InputStream resourceInputStream =
          LiteLoader.class.getResourceAsStream("/classes/" + fileName + ".bin");

      if (resourceInputStream != null) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        for (int readBytes = resourceInputStream.read();
            readBytes >= 0;
            readBytes = resourceInputStream.read()) {
          outputStream.write(readBytes);
        }

        byte[] data = outputStream.toByteArray();

        outputStream.close();
        resourceInputStream.close();

        logger.info("Defining class override for " + binaryClassName);
        mDefineClass.invoke(
            Minecraft.class.getClassLoader(), binaryClassName, data, 0, data.length);
      } else {
        logger.info("Error defining class override for " + binaryClassName + ", file not found");
      }
    } catch (Throwable th) {
      logger.log(Level.WARNING, "Error defining class override for " + binaryClassName, th);
    }
  }
예제 #2
0
    @Override
    public synchronized void flush() throws IOException {
      super.flush();
      String record = this.toString();
      super.reset();

      if (record.length() > 0 && !record.equals(separator)) {
        logger.logp(level, "LoggerOutputStream", "log" + level, record);
      }
    }
예제 #3
0
    @Override
    public synchronized void flush() throws IOException {
      super.flush();
      String record = this.toString();
      super.reset();

      if (record.length() > 0 && !record.equals(separator)) {
        jTerminal.print(record);
        jFrame.repaint();
      }
    }
    /** Read until we see the specified boundary. */
    private byte[] readUntil(String boundary) throws IOException {
      // TODO: is there a blank line before the boundary?
      final ByteArrayOutputStream os = new ByteArrayOutputStream();
      final byte[] boundaryBytes = boundary.getBytes();
      final byte[] matchBuffer = new byte[boundaryBytes.length];

      int matchOffset = 0; // will be nonzero when checking a potential
      // match
      while (true) {
        if (os.size() >= MAX_IMAGE_SIZE)
          throw new IOException("No boundary found in " + MAX_IMAGE_SIZE + " bytes.");
        // TODO: read more efficiently, not 1 at a time.
        final int lenRead = read(matchBuffer, matchOffset, 1);
        if (lenRead < 0) return null; // EOS
        if (matchBuffer[matchOffset] == boundaryBytes[matchOffset]) {
          if (matchOffset == boundaryBytes.length - 1) { // found the boundary
            pushback(matchBuffer, matchOffset + 1); // push it back
            // to be read
            // again
            break;
          } else {
            // keep matching the boundary
            ++matchOffset;
          }

        } else {
          if (matchOffset > 0) { // we had a partial, but not full match - dump it all into
            // the buffer
            os.write(matchBuffer, 0, matchOffset + 1);
            matchOffset = 0;
          } else {
            // completely nonmatching byte
            os.write(matchBuffer, 0, 1);
          }
        }
      }

      final byte[] result = os.toByteArray();
      return result;

      // // the crlf before the boundary is part of the boundary, see
      // // http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
      // // TODO: we should basically add this to the boundary
      //
      // System.out.println("\\r=" + Integer.toHexString('\r'));
      // System.out.println("\\n=" + Integer.toHexString('\n'));
      // System.out.println("" +
      // Integer.toHexString(result[result.length-3]));
      // System.out.println("" +
      // Integer.toHexString(result[result.length-2]));
      // System.out.println("" +
      // Integer.toHexString(result[result.length-1]));
      //
      // final int trim = 2;
      // final byte[] trimmedResult = new byte[result.length - trim];
      // System.arraycopy(result, 0, trimmedResult, 0,
      // trimmedResult.length);
      //
      //
      //
      // return trimmedResult;
    }