1 /* 2 * Copyright (C) 2009 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.escape; 16 17 import static java.util.Objects.requireNonNull; 18 19 import com.google.common.annotations.GwtCompatible; 20 21 /** 22 * Methods factored out so that they can be emulated differently in GWT. 23 * 24 * @author Jesse Wilson 25 */ 26 @GwtCompatible(emulated = true) 27 @ElementTypesAreNonnullByDefault 28 final class Platform { Platform()29 private Platform() {} 30 31 /** Returns a thread-local 1024-char array. */ charBufferFromThreadLocal()32 static char[] charBufferFromThreadLocal() { 33 // requireNonNull accommodates Android's @RecentlyNullable annotation on ThreadLocal.get 34 return requireNonNull(DEST_TL.get()); 35 } 36 37 /** 38 * A thread-local destination buffer to keep us from creating new buffers. The starting size is 39 * 1024 characters. If we grow past this we don't put it back in the threadlocal, we just keep 40 * going and grow as needed. 41 */ 42 private static final ThreadLocal<char[]> DEST_TL = 43 new ThreadLocal<char[]>() { 44 @Override 45 protected char[] initialValue() { 46 return new char[1024]; 47 } 48 }; 49 } 50