src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordedObject.java
changeset 52850 f527b24990d7
parent 50113 caf115bb98ad
child 52981 4eff16f47ae2
equal deleted inserted replaced
52849:eef755718cb2 52850:f527b24990d7
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.jfr.consumer;
    26 package jdk.jfr.consumer;
    27 
    27 
    28 import java.io.IOException;
       
    29 import java.io.PrintWriter;
    28 import java.io.PrintWriter;
    30 import java.io.StringWriter;
    29 import java.io.StringWriter;
    31 import java.time.Duration;
    30 import java.time.Duration;
    32 import java.time.Instant;
    31 import java.time.Instant;
       
    32 import java.time.OffsetDateTime;
    33 import java.util.List;
    33 import java.util.List;
    34 import java.util.Objects;
    34 import java.util.Objects;
    35 
    35 
    36 import jdk.jfr.Timespan;
    36 import jdk.jfr.Timespan;
    37 import jdk.jfr.Timestamp;
    37 import jdk.jfr.Timestamp;
    38 import jdk.jfr.ValueDescriptor;
    38 import jdk.jfr.ValueDescriptor;
    39 import jdk.jfr.internal.PrivateAccess;
    39 import jdk.jfr.internal.PrivateAccess;
    40 import jdk.jfr.internal.cmd.PrettyWriter;
    40 import jdk.jfr.internal.tool.PrettyWriter;
    41 
    41 
    42 /**
    42 /**
    43  * A complex data type that consists of one or more fields.
    43  * A complex data type that consists of one or more fields.
    44  * <p>
    44  * <p>
    45  * This class provides methods to select and query nested objects by passing a
    45  * This class provides methods to select and query nested objects by passing a
   870      */
   870      */
   871     @Override
   871     @Override
   872     final public String toString() {
   872     final public String toString() {
   873         StringWriter s = new StringWriter();
   873         StringWriter s = new StringWriter();
   874         PrettyWriter p = new PrettyWriter(new PrintWriter(s));
   874         PrettyWriter p = new PrettyWriter(new PrintWriter(s));
   875         try {
   875         p.setStackDepth(5);
   876             if (this instanceof RecordedEvent) {
   876         if (this instanceof RecordedEvent) {
   877                 p.print((RecordedEvent) this);
   877             p.print((RecordedEvent) this);
   878             } else {
   878         } else {
   879                 p.print(this, "");
   879             p.print(this, "");
   880             }
   880         }
   881 
   881         p.flush(true);
   882         } catch (IOException e) {
       
   883             // Ignore, should not happen with StringWriter
       
   884         }
       
   885         p.flush();
       
   886         return s.toString();
   882         return s.toString();
       
   883     }
       
   884 
       
   885     // package private for now. Used by EventWriter
       
   886     OffsetDateTime getOffsetDateTime(String name) {
       
   887         return OffsetDateTime.ofInstant(getInstant(name), timeConverter.getZoneOffset());
   887     }
   888     }
   888 
   889 
   889     private static IllegalArgumentException newIllegalArgumentException(String name, String typeName) {
   890     private static IllegalArgumentException newIllegalArgumentException(String name, String typeName) {
   890         return new IllegalArgumentException("Attempt to get field \"" + name + "\" with illegal data type conversion " + typeName);
   891         return new IllegalArgumentException("Attempt to get field \"" + name + "\" with illegal data type conversion " + typeName);
   891     }
   892     }