Attribute (String name, ThrowableConsumer<? super DataOutputStream, ? extends IOException> generator) { BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream(); int start, end; try (DataOutputStream dos = new DataOutputStream(bytes)) { writeClassHeader(dos, 0, ArrayUtil.EMPTY_BYTE_ARRAY); start = dos.size(); generator.consume(dos); end = dos.size(); } catch (IOException e) { throw new RuntimeException(e); } ClassReader reader = new ClassReader(bytes.getInternalBuffer(), 0, bytes.size()); return new Attribute(name) { public Attribute read() { return read(reader, start, end - start, null, 0, null); } }.read(); }