Returns the content of the class file that was built by this ClassWriter.

@return the binary content of the JVMS ClassFile structure that was built by this ClassWriter.
15958
public byte[] toByteArray() {
    // First step: compute the size in bytes of the ClassFile structure.
    // The magic field uses 4 bytes, 10 mandatory fields (minor_version, major_version,
    // constant_pool_count, access_flags, this_class, super_class, interfaces_count, fields_count,
    // methods_count and attributes_count) use 2 bytes each, and each interface uses 2 bytes too.
    int size = 24 + 2 * interfaceCount;
    int fieldsCount = 0;
    FieldWriter fieldWriter = firstField;
    while (fieldWriter != null) {
      ++fieldsCount;
      size += fieldWriter.computeFieldInfoSize();
      fieldWriter = (FieldWriter) fieldWriter.fv;
    }
    int methodsCount = 0;
    MethodWriter methodWriter = firstMethod;
    while (methodWriter != null) {
      ++methodsCount;
      size += methodWriter.computeMethodInfoSize();
      methodWriter = (MethodWriter) methodWriter.mv;
    }
    // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS.
    int attributesCount = 0;
    if (innerClasses != null) {
      ++attributesCount;
      size += 8 + innerClasses.length;
      symbolTable.addConstantUtf8(Constants.INNER_CLASSES);
    }
    if (enclosingClassIndex != 0) {
      ++attributesCount;
      size += 10;
      symbolTable.addConstantUtf8(Constants.ENCLOSING_METHOD);
    }
    if ((accessFlags & Opcodes.ACC_SYNTHETIC) != 0 && (version & 0xFFFF) < Opcodes.V1_5) {
      ++attributesCount;
      size += 6;
      symbolTable.addConstantUtf8(Constants.SYNTHETIC);
    }
    if (signatureIndex != 0) {
      ++attributesCount;
      size += 8;
      symbolTable.addConstantUtf8(Constants.SIGNATURE);
    }
    if (sourceFileIndex != 0) {
      ++attributesCount;
      size += 8;
      symbolTable.addConstantUtf8(Constants.SOURCE_FILE);
    }
    if (debugExtension != null) {
      ++attributesCount;
      size += 6 + debugExtension.length;
      symbolTable.addConstantUtf8(Constants.SOURCE_DEBUG_EXTENSION);
    }
    if ((accessFlags & Opcodes.ACC_DEPRECATED) != 0) {
      ++attributesCount;
      size += 6;
      symbolTable.addConstantUtf8(Constants.DEPRECATED);
    }
    if (symbolTable.computeBootstrapMethodsSize() > 0) {
      ++attributesCount;
      size += symbolTable.computeBootstrapMethodsSize();
    }
    if (firstAttribute != null) {
      attributesCount += firstAttribute.getAttributeCount();
      size += firstAttribute.computeAttributesSize(symbolTable);
    }
    // IMPORTANT: this must be the last part of the ClassFile size computation, because the previous
    // statements can add attribute names to the constant pool, thereby changing its size!
    size += symbolTable.getConstantPoolLength();
    if (symbolTable.getConstantPoolCount() > 0xFFFF) {
      throw new IndexOutOfBoundsException("Class file too large!");
    }

    // Second step: allocate a ByteVector of the correct size (in order to avoid any array copy in
    // dynamic resizes) and fill it with the ClassFile content.
    ByteVector result = new ByteVector(size);
    result.putInt(0xCAFEBABE).putInt(version);
    symbolTable.putConstantPool(result);
    int mask = (version & 0xFFFF) < Opcodes.V1_5 ? Opcodes.ACC_SYNTHETIC : 0;
    result.putShort(accessFlags & ~mask).putShort(thisClass).putShort(superClass);
    result.putShort(interfaceCount);
    for (int i = 0; i < interfaceCount; ++i) {
      result.putShort(interfaces[i]);
    }
    result.putShort(fieldsCount);
    fieldWriter = firstField;
    while (fieldWriter != null) {
      fieldWriter.putFieldInfo(result);
      fieldWriter = (FieldWriter) fieldWriter.fv;
    }
    result.putShort(methodsCount);
    boolean hasFrames = false;
    boolean hasAsmInstructions = false;
    methodWriter = firstMethod;
    while (methodWriter != null) {
      hasFrames |= methodWriter.hasFrames();
      hasAsmInstructions |= methodWriter.hasAsmInstructions();
      methodWriter.putMethodInfo(result);
      methodWriter = (MethodWriter) methodWriter.mv;
    }
    // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS.
    result.putShort(attributesCount);
    if (innerClasses != null) {
      result
          .putShort(symbolTable.addConstantUtf8(Constants.INNER_CLASSES))
          .putInt(innerClasses.length + 2)
          .putShort(numberOfInnerClasses)
          .putByteArray(innerClasses.data, 0, innerClasses.length);
    }
    if (enclosingClassIndex != 0) {
      result
          .putShort(symbolTable.addConstantUtf8(Constants.ENCLOSING_METHOD))
          .putInt(4)
          .putShort(enclosingClassIndex)
          .putShort(enclosingMethodIndex);
    }
    if ((accessFlags & Opcodes.ACC_SYNTHETIC) != 0 && (version & 0xFFFF) < Opcodes.V1_5) {
      result.putShort(symbolTable.addConstantUtf8(Constants.SYNTHETIC)).putInt(0);
    }
    if (signatureIndex != 0) {
      result
          .putShort(symbolTable.addConstantUtf8(Constants.SIGNATURE))
          .putInt(2)
          .putShort(signatureIndex);
    }
    if (sourceFileIndex != 0) {
      result
          .putShort(symbolTable.addConstantUtf8(Constants.SOURCE_FILE))
          .putInt(2)
          .putShort(sourceFileIndex);
    }
    if (debugExtension != null) {
      int length = debugExtension.length;
      result
          .putShort(symbolTable.addConstantUtf8(Constants.SOURCE_DEBUG_EXTENSION))
          .putInt(length)
          .putByteArray(debugExtension.data, 0, length);
    }
    if ((accessFlags & Opcodes.ACC_DEPRECATED) != 0) {
      result.putShort(symbolTable.addConstantUtf8(Constants.DEPRECATED)).putInt(0);
    }
    symbolTable.putBootstrapMethods(result);
    if (firstAttribute != null) {
      firstAttribute.putAttributes(symbolTable, result);
    }

    // Third step: replace the ASM specific instructions, if any.
    if (hasAsmInstructions) {
      return replaceAsmInstructions(result.data, hasFrames);
    } else {
      return result.data;
    }
  }
245394
public String getSourceFile() {
        if ( sourceFile == null )
            if ( parent != null )
                return ((SimpleNode)parent).getSourceFile();
            else
                return "<unknown file>";
        else
            return sourceFile;
    }
158261
public Class defineClass() {
        byte[] bytes;
        try {
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            writeTo(bout);
            bytes = bout.toByteArray();
        } catch (IOException e) {
            InternalError ie = new InternalError(e.toString());
            ie.initCause(e);
            throw ie;
        }

        if (DEBUG) {
            File file = new File(getClassName().replace('.', '/') + ".class");
            try {
                File tempDir = new File(System.getProperty("java.io.tmpdir"));
                file = new File(tempDir, file.getPath());
            } catch (SecurityException e) {
            }
            try {
                file.getParentFile().mkdirs();
                System.out.println("RuntimeClassFile writing to " + file);
                OutputStream out = new FileOutputStream(file);
                out.write(bytes);
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return mLoader.define(getClassName(), bytes);
    }
1170775
public byte[] getBytes() {
		final int len = getVInt();
		final byte[] bytes = new byte[len];
		System.arraycopy(buf, bufPosition, bytes, 0, bytes.length);
		bufPosition += bytes.length;
		return bytes;
	}
984745
public String getContent() {
    	StringBuffer buf = new StringBuffer();
    	for (Iterator i = getChunks().iterator(); i.hasNext(); ) {
    		buf.append(i.next().toString());
    	}
    	return buf.toString();
    }
1021381
public static String getClassPath()
  {
    if (_classPath != null)
      return _classPath;

    String cp = System.getProperty("java.class.path");

    String boot = System.getProperty("sun.boot.class.path");
    if (boot != null && ! boot.equals(""))
      cp = cp + File.pathSeparatorChar + boot;

    Pattern pattern = Pattern.compile("" + File.pathSeparatorChar);

    String []path = pattern.split(cp);

    CharBuffer cb = new CharBuffer();

    for (int i = 0; i < path.length; i++) {
      PathImpl subpath = VfsOld.lookup(path[i]);

      if (subpath.canRead() || subpath.isDirectory()) {
        if (cb.length() > 0)
          cb.append(File.pathSeparatorChar);

        cb.append(path[i]);
      }
    }

    _classPath = cb.toString();

    return _classPath;
  }
982831
public String getClasspath() {
        StringBuilder sb = new StringBuilder();
        boolean firstPass = true;
        Enumeration componentEnum = pathComponents.elements();
        while (componentEnum.hasMoreElements()) {
            if (!firstPass) {
                sb.append(System.getProperty("path.separator"));
            } else {
                firstPass = false;
            }
            sb.append(((File) componentEnum.nextElement()).getAbsolutePath());
        }
        return sb.toString();
    }
419442
private byte[] loadClassBytes(File classFile) throws IOException
	{

		int size = (int) classFile.length();
		byte buff[] = new byte[size];

		FileInputStream fis = new FileInputStream(classFile);
		DataInputStream dis = null;

		try
		{
			dis = new DataInputStream(fis);
			dis.readFully(buff);
		}
		finally
		{
			if(dis != null)
				dis.close();
		}

		return buff;
	}
841996
public File getJarDirectory() {
        if (jarDirectory == null) {
            this.jarDirectory = new File(jarPath).getAbsoluteFile().getParentFile();
        }
        return jarDirectory;
    }
838318
protected final ClassFile getClassFile(String className)
	{
		ClassFile cf=null;
		String filePath=null;
		if(className!=null && !className.isEmpty())
		{
			String rootPath=getClassRootDir();
			if(rootPath.endsWith("/")||rootPath.endsWith("\\"))
			{
			}else
			{
				rootPath=rootPath+File.separator;
			}
			filePath=rootPath+className.replace('.', File.separatorChar)+".class";
		}
		File file=new File(filePath);
		if(file.exists() && file.isFile())
		{
			cf=new ClassFile(className, file.getPath());
			cf.setLastModifyTime(file.lastModified());
		}
		return cf;
	}
321495
public byte[] getLocalFileDataData() {
    // CRC will be added later
    byte[] data = new byte[getLocalFileDataLength().getValue() - WORD];
    System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2);

    byte[] linkArray = getLinkedFile().getBytes(); // Uses default charset - see class Javadoc
    // CheckStyle:MagicNumber OFF
    System.arraycopy(ZipLong.getBytes(linkArray.length),
        0, data, 2, WORD);

    System.arraycopy(ZipShort.getBytes(getUserId()),
        0, data, 6, 2);
    System.arraycopy(ZipShort.getBytes(getGroupId()),
        0, data, 8, 2);

    System.arraycopy(linkArray, 0, data, 10, linkArray.length);
    // CheckStyle:MagicNumber ON

    crc.reset();
    crc.update(data);
    long checksum = crc.getValue();

    byte[] result = new byte[data.length + WORD];
    System.arraycopy(ZipLong.getBytes(checksum), 0, result, 0, WORD);
    System.arraycopy(data, 0, result, WORD, data.length);
    return result;
  }
1231133
@Nonnull
  @ReturnsMutableCopy
  public byte [] getAsByteArray ()
  {
    final byte [] aArray = m_aBuffer.array ();
    final int nOfs = m_aBuffer.arrayOffset ();
    final int nLength = m_aBuffer.position ();

    return ArrayHelper.getCopy (aArray, nOfs, nLength);
  }
109442
protected String resolveJarFile() {
        Class resourceClass = resourceInfo.getResourceClass();
        if (resourceClass == null) return null;
        String classFile = resourceClass.getName().replace(".", "/") + ".class";
        URL classUrl = IOUtils.getResource(classFile);
        String urlProtocol = classUrl.getProtocol();
        if (urlProtocol.equals("jar")) {
            String path = classUrl.getPath();
            return path.substring(0, path.length() - classFile.length() - 1);
        }
        return null;
    }
1043880
public ByteBuffer getByteBuffer() throws IOException
    {
        return rwChannel.map( FileChannel.MapMode.READ_ONLY, 0, file.length() );
    }
1059583
public final byte[] getBytes() {
		final int length = bytes.length;
		final byte[] result = new byte[length];

		// Make a defensive copy
		System.arraycopy(bytes, 0, result, 0, length);

		return result;
	}
202584
public String getContent() {

        if ((m_content.length() == 0) && (getFile() != null)) {
            m_content = new String(getFile().getContents());
        }
        return m_content;
    }
119550
public byte[] getJarBytes() throws EeClassLoaderException {
        DataInputStream dataInputStream = null;
        byte[] bytes;

        try {
            long jarEntrySize = jarEntry.getSize();
            if (jarEntrySize <= 0  ||  jarEntrySize >= Integer.MAX_VALUE) {
                throw new EeClassLoaderException("Invalid size " + jarEntrySize + " for entry " + jarEntry);
            }

            bytes = new byte[(int) jarEntrySize];

            InputStream inputStream = jarFileInfo.getJarFile().getInputStream(jarEntry);
            dataInputStream = new DataInputStream(inputStream);
            dataInputStream.readFully(bytes);
        } catch (IOException e) {
            throw new EeClassLoaderException(null, e);
        } finally {
            if (dataInputStream != null) {
                try {
                    dataInputStream.close();
                } catch (IOException e) {
                    // Ignore
                }
            }
        }

        return bytes;
    }