001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.serializer; 014 015import static org.apache.juneau.collections.JsonMap.*; 016import java.lang.annotation.*; 017import java.lang.reflect.*; 018import java.util.*; 019 020import org.apache.juneau.*; 021import org.apache.juneau.collections.*; 022import org.apache.juneau.internal.*; 023import org.apache.juneau.utils.*; 024 025/** 026 * Subclass of {@link Serializer} for byte-based serializers. 027 * 028 * <h5 class='section'>Notes:</h5><ul> 029 * <li class='note'>This class is thread safe and reusable. 030 * </ul> 031 * 032 * <h5 class='section'>See Also:</h5><ul> 033 * <li class='link'><a class="doclink" href="../../../../index.html#jm.SerializersAndParsers">Serializers and Parsers</a> 034 035 * </ul> 036 */ 037public class OutputStreamSerializer extends Serializer { 038 039 //------------------------------------------------------------------------------------------------------------------- 040 // Static 041 //------------------------------------------------------------------------------------------------------------------- 042 043 /** 044 * Creates a new builder for this object. 045 * 046 * @return A new builder. 047 */ 048 public static Builder create() { 049 return new Builder(); 050 } 051 052 //------------------------------------------------------------------------------------------------------------------- 053 // Builder 054 //------------------------------------------------------------------------------------------------------------------- 055 056 /** 057 * Builder class. 058 */ 059 @FluentSetters 060 public static class Builder extends Serializer.Builder { 061 062 BinaryFormat binaryFormat; 063 064 /** 065 * Constructor, default settings. 066 */ 067 protected Builder() { 068 super(); 069 binaryFormat = env("OutputStreamSerializer.binaryFormat", BinaryFormat.HEX); 070 } 071 072 /** 073 * Copy constructor. 074 * 075 * @param copyFrom The bean to copy from. 076 */ 077 protected Builder(OutputStreamSerializer copyFrom) { 078 super(copyFrom); 079 binaryFormat = copyFrom.binaryFormat; 080 } 081 082 /** 083 * Copy constructor. 084 * 085 * @param copyFrom The builder to copy from. 086 */ 087 protected Builder(Builder copyFrom) { 088 super(copyFrom); 089 binaryFormat = copyFrom.binaryFormat; 090 } 091 092 @Override /* Context.Builder */ 093 public Builder copy() { 094 return new Builder(this); 095 } 096 097 @Override /* Context.Builder */ 098 public OutputStreamSerializer build() { 099 return build(OutputStreamSerializer.class); 100 } 101 102 @Override /* Context.Builder */ 103 public HashKey hashKey() { 104 return HashKey.of( 105 super.hashKey(), 106 binaryFormat 107 ); 108 } 109 110 //----------------------------------------------------------------------------------------------------------------- 111 // Properties 112 //----------------------------------------------------------------------------------------------------------------- 113 114 /** 115 * Binary output format. 116 * 117 * <p> 118 * When using the {@link OutputStreamSerializer#serializeToString(Object)} method on stream-based serializers, this defines the format to use 119 * when converting the resulting byte array to a string. 120 * 121 * <h5 class='section'>Example:</h5> 122 * <p class='bjava'> 123 * <jc>// Create a serializer that serializes to BASE64.</jc> 124 * OutputStreamSerializer <jv>serializer</jv> = MsgPackSerializer 125 * .<jsm>create</jsm>() 126 * .binaryFormat(<jsf>BASE64</jsf>) 127 * .build(); 128 * 129 * <jc>// The bean we want to serialize.</jc> 130 * <jk>public class</jk> MyBean {...} 131 * 132 * <jc>// MessagePack will generate BASE64-encoded string.</jc> 133 * String <jv>msgPack</jv> = <jv>serializer</jv>.serializeToString(<jk>new</jk> MyBean()); 134 * </p> 135 * 136 * @param value 137 * The new value for this property. 138 * <br>The default is {@link BinaryFormat#HEX}. 139 * @return This object. 140 */ 141 @FluentSetter 142 public Builder binaryFormat(BinaryFormat value) { 143 binaryFormat = value; 144 return this; 145 } 146 147 // <FluentSetters> 148 149 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 150 public Builder annotations(Annotation...values) { 151 super.annotations(values); 152 return this; 153 } 154 155 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 156 public Builder apply(AnnotationWorkList work) { 157 super.apply(work); 158 return this; 159 } 160 161 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 162 public Builder applyAnnotations(java.lang.Class<?>...fromClasses) { 163 super.applyAnnotations(fromClasses); 164 return this; 165 } 166 167 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 168 public Builder applyAnnotations(Method...fromMethods) { 169 super.applyAnnotations(fromMethods); 170 return this; 171 } 172 173 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 174 public Builder cache(Cache<HashKey,? extends org.apache.juneau.Context> value) { 175 super.cache(value); 176 return this; 177 } 178 179 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 180 public Builder debug() { 181 super.debug(); 182 return this; 183 } 184 185 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 186 public Builder debug(boolean value) { 187 super.debug(value); 188 return this; 189 } 190 191 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 192 public Builder impl(Context value) { 193 super.impl(value); 194 return this; 195 } 196 197 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 198 public Builder type(Class<? extends org.apache.juneau.Context> value) { 199 super.type(value); 200 return this; 201 } 202 203 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 204 public Builder beanClassVisibility(Visibility value) { 205 super.beanClassVisibility(value); 206 return this; 207 } 208 209 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 210 public Builder beanConstructorVisibility(Visibility value) { 211 super.beanConstructorVisibility(value); 212 return this; 213 } 214 215 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 216 public Builder beanContext(BeanContext value) { 217 super.beanContext(value); 218 return this; 219 } 220 221 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 222 public Builder beanContext(BeanContext.Builder value) { 223 super.beanContext(value); 224 return this; 225 } 226 227 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 228 public Builder beanDictionary(java.lang.Class<?>...values) { 229 super.beanDictionary(values); 230 return this; 231 } 232 233 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 234 public Builder beanFieldVisibility(Visibility value) { 235 super.beanFieldVisibility(value); 236 return this; 237 } 238 239 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 240 public Builder beanInterceptor(Class<?> on, Class<? extends org.apache.juneau.swap.BeanInterceptor<?>> value) { 241 super.beanInterceptor(on, value); 242 return this; 243 } 244 245 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 246 public Builder beanMapPutReturnsOldValue() { 247 super.beanMapPutReturnsOldValue(); 248 return this; 249 } 250 251 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 252 public Builder beanMethodVisibility(Visibility value) { 253 super.beanMethodVisibility(value); 254 return this; 255 } 256 257 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 258 public Builder beanProperties(Map<String,Object> values) { 259 super.beanProperties(values); 260 return this; 261 } 262 263 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 264 public Builder beanProperties(Class<?> beanClass, String properties) { 265 super.beanProperties(beanClass, properties); 266 return this; 267 } 268 269 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 270 public Builder beanProperties(String beanClassName, String properties) { 271 super.beanProperties(beanClassName, properties); 272 return this; 273 } 274 275 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 276 public Builder beanPropertiesExcludes(Map<String,Object> values) { 277 super.beanPropertiesExcludes(values); 278 return this; 279 } 280 281 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 282 public Builder beanPropertiesExcludes(Class<?> beanClass, String properties) { 283 super.beanPropertiesExcludes(beanClass, properties); 284 return this; 285 } 286 287 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 288 public Builder beanPropertiesExcludes(String beanClassName, String properties) { 289 super.beanPropertiesExcludes(beanClassName, properties); 290 return this; 291 } 292 293 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 294 public Builder beanPropertiesReadOnly(Map<String,Object> values) { 295 super.beanPropertiesReadOnly(values); 296 return this; 297 } 298 299 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 300 public Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) { 301 super.beanPropertiesReadOnly(beanClass, properties); 302 return this; 303 } 304 305 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 306 public Builder beanPropertiesReadOnly(String beanClassName, String properties) { 307 super.beanPropertiesReadOnly(beanClassName, properties); 308 return this; 309 } 310 311 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 312 public Builder beanPropertiesWriteOnly(Map<String,Object> values) { 313 super.beanPropertiesWriteOnly(values); 314 return this; 315 } 316 317 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 318 public Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) { 319 super.beanPropertiesWriteOnly(beanClass, properties); 320 return this; 321 } 322 323 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 324 public Builder beanPropertiesWriteOnly(String beanClassName, String properties) { 325 super.beanPropertiesWriteOnly(beanClassName, properties); 326 return this; 327 } 328 329 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 330 public Builder beansRequireDefaultConstructor() { 331 super.beansRequireDefaultConstructor(); 332 return this; 333 } 334 335 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 336 public Builder beansRequireSerializable() { 337 super.beansRequireSerializable(); 338 return this; 339 } 340 341 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 342 public Builder beansRequireSettersForGetters() { 343 super.beansRequireSettersForGetters(); 344 return this; 345 } 346 347 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 348 public Builder dictionaryOn(Class<?> on, java.lang.Class<?>...values) { 349 super.dictionaryOn(on, values); 350 return this; 351 } 352 353 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 354 public Builder disableBeansRequireSomeProperties() { 355 super.disableBeansRequireSomeProperties(); 356 return this; 357 } 358 359 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 360 public Builder disableIgnoreMissingSetters() { 361 super.disableIgnoreMissingSetters(); 362 return this; 363 } 364 365 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 366 public Builder disableIgnoreTransientFields() { 367 super.disableIgnoreTransientFields(); 368 return this; 369 } 370 371 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 372 public Builder disableIgnoreUnknownNullBeanProperties() { 373 super.disableIgnoreUnknownNullBeanProperties(); 374 return this; 375 } 376 377 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 378 public Builder disableInterfaceProxies() { 379 super.disableInterfaceProxies(); 380 return this; 381 } 382 383 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 384 public <T> Builder example(Class<T> pojoClass, T o) { 385 super.example(pojoClass, o); 386 return this; 387 } 388 389 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 390 public <T> Builder example(Class<T> pojoClass, String json) { 391 super.example(pojoClass, json); 392 return this; 393 } 394 395 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 396 public Builder findFluentSetters() { 397 super.findFluentSetters(); 398 return this; 399 } 400 401 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 402 public Builder findFluentSetters(Class<?> on) { 403 super.findFluentSetters(on); 404 return this; 405 } 406 407 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 408 public Builder ignoreInvocationExceptionsOnGetters() { 409 super.ignoreInvocationExceptionsOnGetters(); 410 return this; 411 } 412 413 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 414 public Builder ignoreInvocationExceptionsOnSetters() { 415 super.ignoreInvocationExceptionsOnSetters(); 416 return this; 417 } 418 419 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 420 public Builder ignoreUnknownBeanProperties() { 421 super.ignoreUnknownBeanProperties(); 422 return this; 423 } 424 425 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 426 public Builder ignoreUnknownEnumValues() { 427 super.ignoreUnknownEnumValues(); 428 return this; 429 } 430 431 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 432 public Builder implClass(Class<?> interfaceClass, Class<?> implClass) { 433 super.implClass(interfaceClass, implClass); 434 return this; 435 } 436 437 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 438 public Builder implClasses(Map<Class<?>,Class<?>> values) { 439 super.implClasses(values); 440 return this; 441 } 442 443 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 444 public Builder interfaceClass(Class<?> on, Class<?> value) { 445 super.interfaceClass(on, value); 446 return this; 447 } 448 449 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 450 public Builder interfaces(java.lang.Class<?>...value) { 451 super.interfaces(value); 452 return this; 453 } 454 455 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 456 public Builder locale(Locale value) { 457 super.locale(value); 458 return this; 459 } 460 461 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 462 public Builder mediaType(MediaType value) { 463 super.mediaType(value); 464 return this; 465 } 466 467 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 468 public Builder notBeanClasses(java.lang.Class<?>...values) { 469 super.notBeanClasses(values); 470 return this; 471 } 472 473 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 474 public Builder notBeanPackages(String...values) { 475 super.notBeanPackages(values); 476 return this; 477 } 478 479 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 480 public Builder propertyNamer(Class<? extends org.apache.juneau.PropertyNamer> value) { 481 super.propertyNamer(value); 482 return this; 483 } 484 485 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 486 public Builder propertyNamer(Class<?> on, Class<? extends org.apache.juneau.PropertyNamer> value) { 487 super.propertyNamer(on, value); 488 return this; 489 } 490 491 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 492 public Builder sortProperties() { 493 super.sortProperties(); 494 return this; 495 } 496 497 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 498 public Builder sortProperties(java.lang.Class<?>...on) { 499 super.sortProperties(on); 500 return this; 501 } 502 503 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 504 public Builder stopClass(Class<?> on, Class<?> value) { 505 super.stopClass(on, value); 506 return this; 507 } 508 509 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 510 public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction) { 511 super.swap(normalClass, swappedClass, swapFunction); 512 return this; 513 } 514 515 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 516 public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction, ThrowingFunction<S,T> unswapFunction) { 517 super.swap(normalClass, swappedClass, swapFunction, unswapFunction); 518 return this; 519 } 520 521 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 522 public Builder swaps(java.lang.Class<?>...values) { 523 super.swaps(values); 524 return this; 525 } 526 527 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 528 public Builder timeZone(TimeZone value) { 529 super.timeZone(value); 530 return this; 531 } 532 533 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 534 public Builder typeName(Class<?> on, String value) { 535 super.typeName(on, value); 536 return this; 537 } 538 539 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 540 public Builder typePropertyName(String value) { 541 super.typePropertyName(value); 542 return this; 543 } 544 545 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 546 public Builder typePropertyName(Class<?> on, String value) { 547 super.typePropertyName(on, value); 548 return this; 549 } 550 551 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 552 public Builder useEnumNames() { 553 super.useEnumNames(); 554 return this; 555 } 556 557 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 558 public Builder useJavaBeanIntrospector() { 559 super.useJavaBeanIntrospector(); 560 return this; 561 } 562 563 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 564 public Builder detectRecursions() { 565 super.detectRecursions(); 566 return this; 567 } 568 569 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 570 public Builder detectRecursions(boolean value) { 571 super.detectRecursions(value); 572 return this; 573 } 574 575 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 576 public Builder ignoreRecursions() { 577 super.ignoreRecursions(); 578 return this; 579 } 580 581 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 582 public Builder ignoreRecursions(boolean value) { 583 super.ignoreRecursions(value); 584 return this; 585 } 586 587 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 588 public Builder initialDepth(int value) { 589 super.initialDepth(value); 590 return this; 591 } 592 593 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 594 public Builder maxDepth(int value) { 595 super.maxDepth(value); 596 return this; 597 } 598 599 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 600 public Builder accept(String value) { 601 super.accept(value); 602 return this; 603 } 604 605 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 606 public Builder addBeanTypes() { 607 super.addBeanTypes(); 608 return this; 609 } 610 611 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 612 public Builder addBeanTypes(boolean value) { 613 super.addBeanTypes(value); 614 return this; 615 } 616 617 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 618 public Builder addRootType() { 619 super.addRootType(); 620 return this; 621 } 622 623 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 624 public Builder addRootType(boolean value) { 625 super.addRootType(value); 626 return this; 627 } 628 629 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 630 public Builder keepNullProperties() { 631 super.keepNullProperties(); 632 return this; 633 } 634 635 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 636 public Builder keepNullProperties(boolean value) { 637 super.keepNullProperties(value); 638 return this; 639 } 640 641 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 642 public Builder listener(Class<? extends org.apache.juneau.serializer.SerializerListener> value) { 643 super.listener(value); 644 return this; 645 } 646 647 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 648 public Builder produces(String value) { 649 super.produces(value); 650 return this; 651 } 652 653 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 654 public Builder sortCollections() { 655 super.sortCollections(); 656 return this; 657 } 658 659 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 660 public Builder sortCollections(boolean value) { 661 super.sortCollections(value); 662 return this; 663 } 664 665 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 666 public Builder sortMaps() { 667 super.sortMaps(); 668 return this; 669 } 670 671 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 672 public Builder sortMaps(boolean value) { 673 super.sortMaps(value); 674 return this; 675 } 676 677 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 678 public Builder trimEmptyCollections() { 679 super.trimEmptyCollections(); 680 return this; 681 } 682 683 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 684 public Builder trimEmptyCollections(boolean value) { 685 super.trimEmptyCollections(value); 686 return this; 687 } 688 689 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 690 public Builder trimEmptyMaps() { 691 super.trimEmptyMaps(); 692 return this; 693 } 694 695 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 696 public Builder trimEmptyMaps(boolean value) { 697 super.trimEmptyMaps(value); 698 return this; 699 } 700 701 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 702 public Builder trimStrings() { 703 super.trimStrings(); 704 return this; 705 } 706 707 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 708 public Builder trimStrings(boolean value) { 709 super.trimStrings(value); 710 return this; 711 } 712 713 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 714 public Builder uriContext(UriContext value) { 715 super.uriContext(value); 716 return this; 717 } 718 719 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 720 public Builder uriRelativity(UriRelativity value) { 721 super.uriRelativity(value); 722 return this; 723 } 724 725 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 726 public Builder uriResolution(UriResolution value) { 727 super.uriResolution(value); 728 return this; 729 } 730 731 // </FluentSetters> 732 } 733 734 //------------------------------------------------------------------------------------------------------------------- 735 // Instance 736 //------------------------------------------------------------------------------------------------------------------- 737 738 final BinaryFormat binaryFormat; 739 740 /** 741 * Constructor. 742 * 743 * @param builder 744 * The builder for this object. 745 */ 746 protected OutputStreamSerializer(Builder builder) { 747 super(builder); 748 749 binaryFormat = builder.binaryFormat; 750 } 751 752 @Override /* Context */ 753 public OutputStreamSerializerSession.Builder createSession() { 754 return OutputStreamSerializerSession.create(this); 755 } 756 757 @Override /* Context */ 758 public OutputStreamSerializerSession getSession() { 759 return createSession().build(); 760 } 761 762 @Override /* Serializer */ 763 public final boolean isWriterSerializer() { 764 return false; 765 } 766 767 /** 768 * Convenience method for serializing an object to a <code><jk>byte</jk></code>. 769 * 770 * @param o The object to serialize. 771 * @return The output serialized to a byte array. 772 * @throws SerializeException If a problem occurred trying to convert the output. 773 */ 774 @Override 775 public final byte[] serialize(Object o) throws SerializeException { 776 return getSession().serialize(o); 777 } 778 779 //----------------------------------------------------------------------------------------------------------------- 780 // Properties 781 //----------------------------------------------------------------------------------------------------------------- 782 783 /** 784 * Binary output format. 785 * 786 * @see Builder#binaryFormat(BinaryFormat) 787 * @return 788 * The format to use for the {@link #serializeToString(Object)} method on stream-based serializers when converting byte arrays to strings. 789 */ 790 protected final BinaryFormat getBinaryFormat() { 791 return binaryFormat; 792 } 793 794 //----------------------------------------------------------------------------------------------------------------- 795 // Other methods 796 //----------------------------------------------------------------------------------------------------------------- 797 798 @Override /* Context */ 799 protected JsonMap properties() { 800 return filteredMap("binaryFormat", binaryFormat); 801 } 802}