/** * Writes the default ConfVars out to a byte array and returns an input * stream wrapping that byte array. * * We need this in order to initialize the ConfVar properties * in the underling Configuration object using the addResource(InputStream) * method. * * It is important to use a LoopingByteArrayInputStream because it turns out * addResource(InputStream) is broken since Configuration tries to read the * entire contents of the same InputStream repeatedly without resetting it. * LoopingByteArrayInputStream has special logic to handle this. */ private static synchronized InputStream getConfVarInputStream() { if (confVarByteArray == null) { try { // Create a Hadoop configuration without inheriting default settings. Configuration conf = new Configuration(false); applyDefaultNonNullConfVars(conf); ByteArrayOutputStream confVarBaos = new ByteArrayOutputStream(); conf.writeXml(confVarBaos); confVarByteArray = confVarBaos.toByteArray(); } catch (Exception e) { // We're pretty screwed if we can't load the default conf vars throw new RuntimeException("Failed to initialize default Hive configuration variables!", e); } } return new LoopingByteArrayInputStream(confVarByteArray); }
@Override public synchronized int available() { return getByteArrayInputStream().available(); }
@Override public synchronized int read() { return getByteArrayInputStream().read(); }
/** * Writes the default ConfVars out to a byte array and returns an input * stream wrapping that byte array. * * We need this in order to initialize the ConfVar properties * in the underling Configuration object using the addResource(InputStream) * method. * * It is important to use a LoopingByteArrayInputStream because it turns out * addResource(InputStream) is broken since Configuration tries to read the * entire contents of the same InputStream repeatedly without resetting it. * LoopingByteArrayInputStream has special logic to handle this. */ private static synchronized InputStream getConfVarInputStream() { if (confVarByteArray == null) { try { Configuration conf = new Configuration(); applyDefaultNonNullConfVars(conf); ByteArrayOutputStream confVarBaos = new ByteArrayOutputStream(); conf.writeXml(confVarBaos); confVarByteArray = confVarBaos.toByteArray(); } catch (Exception e) { // We're pretty screwed if we can't load the default conf vars throw new RuntimeException("Failed to initialize default Hive configuration variables!", e); } } return new LoopingByteArrayInputStream(confVarByteArray); }
@Override public int read(byte[] arg0) throws IOException { return getByteArrayInputStream().read(arg0); }
/** * Writes the default ConfVars out to a byte array and returns an input * stream wrapping that byte array. * * We need this in order to initialize the ConfVar properties * in the underling Configuration object using the addResource(InputStream) * method. * * It is important to use a LoopingByteArrayInputStream because it turns out * addResource(InputStream) is broken since Configuration tries to read the * entire contents of the same InputStream repeatedly without resetting it. * LoopingByteArrayInputStream has special logic to handle this. */ private static synchronized InputStream getConfVarInputStream() { if (confVarByteArray == null) { try { // Create a Hadoop configuration without inheriting default settings. Configuration conf = new Configuration(false); applyDefaultNonNullConfVars(conf); ByteArrayOutputStream confVarBaos = new ByteArrayOutputStream(); conf.writeXml(confVarBaos); confVarByteArray = confVarBaos.toByteArray(); } catch (Exception e) { // We're pretty screwed if we can't load the default conf vars throw new RuntimeException("Failed to initialize default Hive configuration variables!", e); } } return new LoopingByteArrayInputStream(confVarByteArray); }
@Override public synchronized int read(byte[] arg0, int arg1, int arg2) { return getByteArrayInputStream().read(arg0, arg1, arg2); }
/** * Writes the default ConfVars out to a byte array and returns an input * stream wrapping that byte array. * * We need this in order to initialize the ConfVar properties * in the underling Configuration object using the addResource(InputStream) * method. * * It is important to use a LoopingByteArrayInputStream because it turns out * addResource(InputStream) is broken since Configuration tries to read the * entire contents of the same InputStream repeatedly without resetting it. * LoopingByteArrayInputStream has special logic to handle this. */ private static synchronized InputStream getConfVarInputStream() { if (confVarByteArray == null) { try { // Create a Hadoop configuration without inheriting default settings. Configuration conf = new Configuration(false); applyDefaultNonNullConfVars(conf); ByteArrayOutputStream confVarBaos = new ByteArrayOutputStream(); conf.writeXml(confVarBaos); confVarByteArray = confVarBaos.toByteArray(); } catch (Exception e) { // We're pretty screwed if we can't load the default conf vars throw new RuntimeException("Failed to initialize default Hive configuration variables!", e); } } return new LoopingByteArrayInputStream(confVarByteArray); }
@Override public void close() throws IOException { getByteArrayInputStream().reset(); // According to the Java documentation this does nothing, but just in case getByteArrayInputStream().close(); }
@Override public synchronized long skip(long arg0) { return getByteArrayInputStream().skip(arg0); }
@Override public boolean markSupported() { return getByteArrayInputStream().markSupported(); }
@Override public synchronized void reset() { getByteArrayInputStream().reset(); }
@Override public void mark(int arg0) { getByteArrayInputStream().mark(arg0); }
@Override public int read(byte[] arg0) throws IOException { return getByteArrayInputStream().read(arg0); }
@Override public synchronized int read(byte[] arg0, int arg1, int arg2) { return getByteArrayInputStream().read(arg0, arg1, arg2); }
@Override public synchronized int read() { return getByteArrayInputStream().read(); }
@Override public synchronized int available() { return getByteArrayInputStream().available(); }
@Override public synchronized int read() { return getByteArrayInputStream().read(); }
@Override public synchronized int read(byte[] arg0, int arg1, int arg2) { return getByteArrayInputStream().read(arg0, arg1, arg2); }
@Override public synchronized int available() { return getByteArrayInputStream().available(); }