title: Is it more efficient to convert an exception's stack trace into byte[] array or ByteBuffer (Java)?
body: <p>I need to log the exception into the database. The database API states I can either pass the value as ByteBuffer or as byte[] array. So which is more efficient?</p>
  
  <pre><code>private final static byte[] getThrowableStackTraceBytes(Throwable throwable) {
      StringWriter throwableStackTraceStringWriter = new StringWriter();
      throwable.printStackTrace(new PrintWriter(throwableStackTraceStringWriter));
      return throwableStackTraceStringWriter.toString().getBytes();
  }
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>private final static ByteBuffer getThrowableStackTraceByteBuffer(Throwable throwable) {
      ByteArrayOutputStream throwableStackTraceByteArrayOutputStream = new ByteArrayOutputStream();
      throwable.printStackTrace(new PrintStream(throwableStackTraceByteArrayOutputStream));
      ByteBuffer throwableByteBuffer = ByteBuffer.wrap(throwableStackTraceByteArrayOutputStream.toByteArray());
      return throwableByteBuffer;
  }
  </code></pre>
  
  <p>I think the overall operation will be more efficient if I were to use ByteBuffer, especially when it is handled after it is being passed into the database method. Am I right?</p>
  
  <p>(Specifically, I need to log the exception into Hypertable, and it uses the Thrift Java API.)</p>