Java Code Examples for org.apache.avro.io.Encoder#writeString()

The following examples show how to use org.apache.avro.io.Encoder#writeString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueWriters.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public void write(Object s, Encoder encoder) throws IOException {
  // use getBytes because it may return the backing byte array if available.
  // otherwise, it copies to a new byte array, which is still cheaper than Avro
  // calling toString, which incurs encoding costs
  if (s instanceof Utf8) {
    encoder.writeString((Utf8) s);
  } else if (s instanceof String) {
    encoder.writeString(new Utf8((String) s));
  } else if (s == null) {
    throw new IllegalArgumentException("Cannot write null to required string column");
  } else {
    throw new IllegalArgumentException(
        "Cannot write unknown string type: " + s.getClass().getName() + ": " + s.toString());
  }
}
 
Example 2
Source File: ValueWriters.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public void write(Object s, Encoder encoder) throws IOException {
  // use getBytes because it may return the backing byte array if available.
  // otherwise, it copies to a new byte array, which is still cheaper than Avro
  // calling toString, which incurs encoding costs
  if (s instanceof Utf8) {
    encoder.writeString((Utf8) s);
  } else if (s instanceof String) {
    encoder.writeString(new Utf8((String) s));
  } else if (s == null) {
    throw new IllegalArgumentException("Cannot write null to required string column");
  } else {
    throw new IllegalArgumentException(
        "Cannot write unknown string type: " + s.getClass().getName() + ": " + s.toString());
  }
}
 
Example 3
Source File: SparkValueWriters.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void write(UTF8String s, Encoder encoder) throws IOException {
  // use getBytes because it may return the backing byte array if available.
  // otherwise, it copies to a new byte array, which is still cheaper than Avro
  // calling toString, which incurs encoding costs
  encoder.writeString(new Utf8(s.getBytes()));
}
 
Example 4
Source File: SparkValueWriters.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public void write(UTF8String s, Encoder encoder) throws IOException {
  // use getBytes because it may return the backing byte array if available.
  // otherwise, it copies to a new byte array, which is still cheaper than Avro
  // calling toString, which incurs encoding costs
  encoder.writeString(new Utf8(s.getBytes()));
}
 
Example 5
Source File: ValueWriters.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Utf8 s, Encoder encoder) throws IOException {
  encoder.writeString(s);
}
 
Example 6
Source File: ValueWriters.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Utf8 s, Encoder encoder) throws IOException {
  encoder.writeString(s);
}