List of usage examples for java.lang Byte toString
public static String toString(byte b)
From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java
/** * Wipe disk for the specified cell/* ww w. j a v a2 s. c om*/ * @param cell the cell to wipe the disks on * @return int 0 on success, -1 on failure */ public int wipeDisks(HCCell cell) throws MgmtException, ConnectException, PermissionException { if (!loggedIn()) throw new PermissionException(); Object[] params = { Long.toString(this._sessionId), Byte.toString(cell.getCellId()) }; this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_WIPE_CELL_DISKS, params, "wipeDisks"); BigInteger result = cell.wipe(new StatusCallback(), BigInteger.valueOf(0)); return result.intValue(); }
From source file:org.ariose.util.SMPPSender.java
/** * Gets a property and converts it into byte. *///from w ww. jav a 2 s . co m private byte getByteProperty(String propName, byte defaultValue) { return Byte.parseByte(properties.getProperty(propName, Byte.toString(defaultValue))); }
From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.JobControlCompiler.java
/** * The method that creates the Job corresponding to a MapReduceOper. * The assumption is that/* w w w .j a va 2 s . co m*/ * every MapReduceOper will have a load and a store. The JobConf removes * the load operator and serializes the input filespec so that PigInputFormat can * take over the creation of splits. It also removes the store operator * and serializes the output filespec so that PigOutputFormat can take over * record writing. The remaining portion of the map plan and reduce plans are * serialized and stored for the PigMapReduce or PigMapOnly objects to take over * the actual running of the plans. * The Mapper & Reducer classes and the required key value formats are set. * Checks if this is a map only job and uses PigMapOnly class as the mapper * and uses PigMapReduce otherwise. * If it is a Map Reduce job, it is bound to have a package operator. Remove it from * the reduce plan and serializes it so that the PigMapReduce class can use it to package * the indexed tuples received by the reducer. * @param mro - The MapReduceOper for which the JobConf is required * @param config - the Configuration object from which JobConf is built * @param pigContext - The PigContext passed on from execution engine * @return Job corresponding to mro * @throws JobCreationException */ @SuppressWarnings({ "unchecked" }) private Job getJob(MROperPlan plan, MapReduceOper mro, Configuration config, PigContext pigContext) throws JobCreationException { org.apache.hadoop.mapreduce.Job nwJob = null; try { nwJob = new org.apache.hadoop.mapreduce.Job(config); } catch (Exception e) { throw new JobCreationException(e); } Configuration conf = nwJob.getConfiguration(); ArrayList<FileSpec> inp = new ArrayList<FileSpec>(); ArrayList<List<OperatorKey>> inpTargets = new ArrayList<List<OperatorKey>>(); ArrayList<String> inpSignatureLists = new ArrayList<String>(); ArrayList<Long> inpLimits = new ArrayList<Long>(); ArrayList<POStore> storeLocations = new ArrayList<POStore>(); Path tmpLocation = null; // add settings for pig statistics String setScriptProp = conf.get(PigConfiguration.PIG_SCRIPT_INFO_ENABLED, "true"); if (setScriptProp.equalsIgnoreCase("true")) { MRScriptState ss = MRScriptState.get(); ss.addSettingsToConf(mro, conf); } conf.set(MRConfiguration.MAPPER_NEW_API, "true"); conf.set(MRConfiguration.REDUCER_NEW_API, "true"); String buffPercent = conf.get(MRConfiguration.JOB_REDUCE_MARKRESET_BUFFER_PERCENT); if (buffPercent == null || Double.parseDouble(buffPercent) <= 0) { log.info(MRConfiguration.JOB_REDUCE_MARKRESET_BUFFER_PERCENT + " is not set, set to default 0.3"); conf.set(MRConfiguration.JOB_REDUCE_MARKRESET_BUFFER_PERCENT, "0.3"); } else { log.info(MRConfiguration.JOB_REDUCE_MARKRESET_BUFFER_PERCENT + " is set to " + conf.get(MRConfiguration.JOB_REDUCE_MARKRESET_BUFFER_PERCENT)); } configureCompression(conf); try { //Process the POLoads List<POLoad> lds = PlanHelper.getPhysicalOperators(mro.mapPlan, POLoad.class); if (lds != null && lds.size() > 0) { for (POLoad ld : lds) { LoadFunc lf = ld.getLoadFunc(); lf.setLocation(ld.getLFile().getFileName(), nwJob); //Store the inp filespecs inp.add(ld.getLFile()); } } if (!mro.reducePlan.isEmpty()) { log.info("Reduce phase detected, estimating # of required reducers."); adjustNumReducers(plan, mro, nwJob); } else { nwJob.setNumReduceTasks(0); } if (!pigContext.inIllustrator && !pigContext.getExecType().isLocal()) { if (okToRunLocal(nwJob, mro, lds)) { log.info(SMALL_JOB_LOG_MSG); // override with the default conf to run in local mode for (Entry<String, String> entry : defaultConf) { String key = entry.getKey(); if (key.equals(MRConfiguration.REDUCE_TASKS) || key.equals(MRConfiguration.JOB_REDUCES)) { // this must not be set back to the default in case it has been set to 0 for example. continue; } if (key.startsWith("fs.")) { // we don't want to change fs settings back continue; } if (key.startsWith("io.")) { // we don't want to change io settings back continue; } String value = entry.getValue(); if (conf.get(key) == null || !conf.get(key).equals(value)) { conf.set(key, value); } } conf.setBoolean(PigImplConstants.CONVERTED_TO_LOCAL, true); } else { log.info(BIG_JOB_LOG_MSG); // Search to see if we have any UDF/LoadFunc/StoreFunc that need to pack things into the // distributed cache. List<String> cacheFiles = new ArrayList<String>(); List<String> shipFiles = new ArrayList<String>(); UdfCacheShipFilesVisitor mapUdfCacheFileVisitor = new UdfCacheShipFilesVisitor(mro.mapPlan); mapUdfCacheFileVisitor.visit(); cacheFiles.addAll(mapUdfCacheFileVisitor.getCacheFiles()); shipFiles.addAll(mapUdfCacheFileVisitor.getShipFiles()); UdfCacheShipFilesVisitor reduceUdfCacheFileVisitor = new UdfCacheShipFilesVisitor( mro.reducePlan); reduceUdfCacheFileVisitor.visit(); cacheFiles.addAll(reduceUdfCacheFileVisitor.getCacheFiles()); shipFiles.addAll(reduceUdfCacheFileVisitor.getShipFiles()); setupDistributedCache(pigContext, conf, cacheFiles.toArray(new String[] {}), false); // Setup the DistributedCache for this job List<URL> allJars = new ArrayList<URL>(); for (URL extraJar : pigContext.extraJars) { if (!allJars.contains(extraJar)) { allJars.add(extraJar); } } for (String udf : mro.UDFs) { Class clazz = pigContext.getClassForAlias(udf); if (clazz != null) { String jar = JarManager.findContainingJar(clazz); if (jar != null) { URL jarURL = new File(jar).toURI().toURL(); if (!allJars.contains(jarURL)) { allJars.add(jarURL); } } } } for (String scriptJar : pigContext.scriptJars) { URL jar = new File(scriptJar).toURI().toURL(); if (!allJars.contains(jar)) { allJars.add(jar); } } for (String shipFile : shipFiles) { URL jar = new File(shipFile).toURI().toURL(); if (!allJars.contains(jar)) { allJars.add(jar); } } for (String defaultJar : JarManager.getDefaultJars()) { URL jar = new File(defaultJar).toURI().toURL(); if (!allJars.contains(jar)) { allJars.add(jar); } } for (URL jar : allJars) { boolean predeployed = false; for (String predeployedJar : pigContext.predeployedJars) { if (predeployedJar.contains(new File(jar.toURI()).getName())) { predeployed = true; } } if (!predeployed) { if (jar.getFile().toLowerCase().endsWith(".jar")) { putJarOnClassPathThroughDistributedCache(pigContext, conf, jar); } else { setupDistributedCache(pigContext, conf, new String[] { jar.getPath() }, true); } } } File scriptUDFJarFile = JarManager.createPigScriptUDFJar(pigContext); if (scriptUDFJarFile != null) { putJarOnClassPathThroughDistributedCache(pigContext, conf, scriptUDFJarFile.toURI().toURL()); } } } for (String udf : mro.UDFs) { if (udf.contains("GFCross")) { Object func = PigContext.instantiateFuncFromSpec(new FuncSpec(udf)); if (func instanceof GFCross) { String crossKey = ((GFCross) func).getCrossKey(); conf.set(PigImplConstants.PIG_CROSS_PARALLELISM + "." + crossKey, Integer.toString(mro.getRequestedParallelism())); } } } if (lds != null && lds.size() > 0) { for (POLoad ld : lds) { //Store the target operators for tuples read //from this input List<PhysicalOperator> ldSucs = mro.mapPlan.getSuccessors(ld); List<OperatorKey> ldSucKeys = new ArrayList<OperatorKey>(); if (ldSucs != null) { for (PhysicalOperator operator2 : ldSucs) { ldSucKeys.add(operator2.getOperatorKey()); } } inpTargets.add(ldSucKeys); inpSignatureLists.add(ld.getSignature()); inpLimits.add(ld.getLimit()); //Remove the POLoad from the plan if (!pigContext.inIllustrator) mro.mapPlan.remove(ld); } } if (Utils.isLocal(pigContext, conf)) { ConfigurationUtil.replaceConfigForLocalMode(conf); } conf.set(PigInputFormat.PIG_INPUTS, ObjectSerializer.serialize(inp)); conf.set(PigInputFormat.PIG_INPUT_TARGETS, ObjectSerializer.serialize(inpTargets)); conf.set(PigInputFormat.PIG_INPUT_SIGNATURES, ObjectSerializer.serialize(inpSignatureLists)); conf.set(PigInputFormat.PIG_INPUT_LIMITS, ObjectSerializer.serialize(inpLimits)); // Removing job credential entry before serializing pigcontext into jobconf // since this path would be invalid for the new job being created pigContext.getProperties().remove("mapreduce.job.credentials.binary"); conf.setBoolean(PigImplConstants.PIG_EXECTYPE_MODE_LOCAL, pigContext.getExecType().isLocal()); conf.set(PigImplConstants.PIG_LOG4J_PROPERTIES, ObjectSerializer.serialize(pigContext.getLog4jProperties())); conf.set("udf.import.list", ObjectSerializer.serialize(PigContext.getPackageImportList())); // this is for unit tests since some don't create PigServer // if user specified the job name using -D switch, Pig won't reset the name then. if (System.getProperty(MRConfiguration.JOB_NAME) == null && pigContext.getProperties().getProperty(PigContext.JOB_NAME) != null) { nwJob.setJobName(pigContext.getProperties().getProperty(PigContext.JOB_NAME)); } if (pigContext.getProperties().getProperty(PigContext.JOB_PRIORITY) != null) { // If the job priority was set, attempt to get the corresponding enum value // and set the hadoop job priority. String jobPriority = pigContext.getProperties().getProperty(PigContext.JOB_PRIORITY).toUpperCase(); try { // Allow arbitrary case; the Hadoop job priorities are all upper case. conf.set(MRConfiguration.JOB_PRIORITY, JobPriority.valueOf(jobPriority).toString()); } catch (IllegalArgumentException e) { StringBuffer sb = new StringBuffer("The job priority must be one of ["); JobPriority[] priorities = JobPriority.values(); for (int i = 0; i < priorities.length; ++i) { if (i > 0) sb.append(", "); sb.append(priorities[i]); } sb.append("]. You specified [" + jobPriority + "]"); throw new JobCreationException(sb.toString()); } } setupDistributedCache(pigContext, conf, pigContext.getProperties(), "pig.streaming.ship.files", true); setupDistributedCache(pigContext, conf, pigContext.getProperties(), "pig.streaming.cache.files", false); nwJob.setInputFormatClass(PigInputFormat.class); // tmp file compression setups // PIG-3741 This must be done before setStoreLocation on POStores Utils.setTmpFileCompressionOnConf(pigContext, conf); //Process POStore and remove it from the plan LinkedList<POStore> mapStores = PlanHelper.getPhysicalOperators(mro.mapPlan, POStore.class); LinkedList<POStore> reduceStores = PlanHelper.getPhysicalOperators(mro.reducePlan, POStore.class); for (POStore st : mapStores) { storeLocations.add(st); StoreFuncInterface sFunc = st.getStoreFunc(); sFunc.setStoreLocation(st.getSFile().getFileName(), nwJob); if (sFunc instanceof OverwritableStoreFunc) { OverwritableStoreFunc osf = (OverwritableStoreFunc) sFunc; if (osf.shouldOverwrite()) { osf.cleanupOutput(st, nwJob); } } } for (POStore st : reduceStores) { storeLocations.add(st); StoreFuncInterface sFunc = st.getStoreFunc(); sFunc.setStoreLocation(st.getSFile().getFileName(), nwJob); if (sFunc instanceof OverwritableStoreFunc) { OverwritableStoreFunc osf = (OverwritableStoreFunc) sFunc; if (osf.shouldOverwrite()) { osf.cleanupOutput(st, nwJob); } } } setOutputFormat(nwJob); if (mapStores.size() + reduceStores.size() == 1) { // single store case log.info("Setting up single store job"); POStore st; if (reduceStores.isEmpty()) { st = mapStores.get(0); if (!pigContext.inIllustrator) mro.mapPlan.remove(st); } else { st = reduceStores.get(0); if (!pigContext.inIllustrator) mro.reducePlan.remove(st); } MapRedUtil.setupStreamingDirsConfSingle(st, pigContext, conf); } else if (mapStores.size() + reduceStores.size() > 0) { // multi store case log.info("Setting up multi store job"); MapRedUtil.setupStreamingDirsConfMulti(pigContext, conf); boolean disableCounter = conf.getBoolean("pig.disable.counter", false); if (disableCounter) { log.info("Disable Pig custom output counters"); } int idx = 0; for (POStore sto : storeLocations) { sto.setDisableCounter(disableCounter); sto.setMultiStore(true); sto.setIndex(idx++); } } // store map key type // this is needed when the key is null to create // an appropriate NullableXXXWritable object conf.set("pig.map.keytype", ObjectSerializer.serialize(new byte[] { mro.mapKeyType })); // set parent plan in all operators in map and reduce plans // currently the parent plan is really used only when POStream is present in the plan new PhyPlanSetter(mro.mapPlan).visit(); new PhyPlanSetter(mro.combinePlan).visit(); new PhyPlanSetter(mro.reducePlan).visit(); // this call modifies the ReplFiles names of POFRJoin operators // within the MR plans, must be called before the plans are // serialized setupDistributedCacheForJoin(mro, pigContext, conf); SchemaTupleFrontend.copyAllGeneratedToDistributedCache(pigContext, conf); POPackage pack = null; if (mro.reducePlan.isEmpty()) { //MapOnly Job nwJob.setMapperClass(PigMapOnly.Map.class); if (!pigContext.inIllustrator) conf.set("pig.mapPlan", ObjectSerializer.serialize(mro.mapPlan)); if (mro.isEndOfAllInputSetInMap()) { // this is used in Map.close() to decide whether the // pipeline needs to be rerun one more time in the close() // The pipeline is rerun if there either was a stream or POMergeJoin conf.set(END_OF_INP_IN_MAP, "true"); } } else { //Map Reduce Job //Process the POPackage operator and remove it from the reduce plan if (!mro.combinePlan.isEmpty()) { POPackage combPack = (POPackage) mro.combinePlan.getRoots().get(0); mro.combinePlan.remove(combPack); nwJob.setCombinerClass(PigCombiner.Combine.class); conf.set("pig.combinePlan", ObjectSerializer.serialize(mro.combinePlan)); conf.set("pig.combine.package", ObjectSerializer.serialize(combPack)); } else if (mro.needsDistinctCombiner()) { nwJob.setCombinerClass(DistinctCombiner.Combine.class); log.info("Setting identity combiner class."); } pack = (POPackage) mro.reducePlan.getRoots().get(0); if (!pigContext.inIllustrator) { mro.reducePlan.remove(pack); } nwJob.setMapperClass(PigMapReduce.Map.class); nwJob.setReducerClass(PigMapReduce.Reduce.class); if (mro.customPartitioner != null) nwJob.setPartitionerClass(PigContext.resolveClassName(mro.customPartitioner)); if (!pigContext.inIllustrator) conf.set("pig.mapPlan", ObjectSerializer.serialize(mro.mapPlan)); if (mro.isEndOfAllInputSetInMap()) { // this is used in Map.close() to decide whether the // pipeline needs to be rerun one more time in the close() // The pipeline is rerun only if there was a stream or merge-join. conf.set(END_OF_INP_IN_MAP, "true"); } if (!pigContext.inIllustrator) conf.set("pig.reducePlan", ObjectSerializer.serialize(mro.reducePlan)); if (mro.isEndOfAllInputSetInReduce()) { // this is used in Map.close() to decide whether the // pipeline needs to be rerun one more time in the close() // The pipeline is rerun only if there was a stream conf.set("pig.stream.in.reduce", "true"); } if (!pigContext.inIllustrator) conf.set("pig.reduce.package", ObjectSerializer.serialize(pack)); conf.set("pig.reduce.key.type", Byte.toString(pack.getPkgr().getKeyType())); if (mro.getUseSecondaryKey()) { nwJob.setGroupingComparatorClass(PigSecondaryKeyGroupComparator.class); nwJob.setPartitionerClass(SecondaryKeyPartitioner.class); nwJob.setSortComparatorClass(PigSecondaryKeyComparator.class); nwJob.setOutputKeyClass(NullableTuple.class); conf.set("pig.secondarySortOrder", ObjectSerializer.serialize(mro.getSecondarySortOrder())); } else { Class<? extends WritableComparable> keyClass = HDataType .getWritableComparableTypes(pack.getPkgr().getKeyType()).getClass(); nwJob.setOutputKeyClass(keyClass); selectComparator(mro, pack.getPkgr().getKeyType(), nwJob); } nwJob.setOutputValueClass(NullableTuple.class); } if (mro.isGlobalSort() || mro.isLimitAfterSort()) { if (mro.isGlobalSort()) { String symlink = addSingleFileToDistributedCache(pigContext, conf, mro.getQuantFile(), "pigsample"); conf.set("pig.quantilesFile", symlink); nwJob.setPartitionerClass(WeightedRangePartitioner.class); } if (mro.isUDFComparatorUsed) { boolean usercomparator = false; for (String compFuncSpec : mro.UDFs) { Class comparator = PigContext.resolveClassName(compFuncSpec); if (ComparisonFunc.class.isAssignableFrom(comparator)) { nwJob.setMapperClass(PigMapReduce.MapWithComparator.class); nwJob.setReducerClass(PigMapReduce.ReduceWithComparator.class); conf.set("pig.reduce.package", ObjectSerializer.serialize(pack)); conf.set("pig.usercomparator", "true"); nwJob.setOutputKeyClass(NullableTuple.class); nwJob.setSortComparatorClass(comparator); usercomparator = true; break; } } if (!usercomparator) { String msg = "Internal error. Can't find the UDF comparator"; throw new IOException(msg); } } else { conf.set("pig.sortOrder", ObjectSerializer.serialize(mro.getSortOrder())); } } if (mro.isSkewedJoin()) { String symlink = addSingleFileToDistributedCache(pigContext, conf, mro.getSkewedJoinPartitionFile(), "pigdistkey"); conf.set("pig.keyDistFile", symlink); nwJob.setPartitionerClass(SkewedPartitioner.class); nwJob.setMapperClass(PigMapReduce.MapWithPartitionIndex.class); nwJob.setMapOutputKeyClass(NullablePartitionWritable.class); nwJob.setGroupingComparatorClass(PigGroupingPartitionWritableComparator.class); } if (mro.isCounterOperation()) { if (mro.isRowNumber()) { nwJob.setMapperClass(PigMapReduceCounter.PigMapCounter.class); } else { nwJob.setReducerClass(PigMapReduceCounter.PigReduceCounter.class); } } if (mro.isRankOperation()) { Iterator<String> operationIDs = mro.getRankOperationId().iterator(); while (operationIDs.hasNext()) { String operationID = operationIDs.next(); Iterator<Pair<String, Long>> itPairs = globalCounters.get(operationID).iterator(); Pair<String, Long> pair = null; while (itPairs.hasNext()) { pair = itPairs.next(); conf.setLong(pair.first, pair.second); } } } if (!pigContext.inIllustrator) { // unset inputs for POStore, otherwise, map/reduce plan will be unnecessarily deserialized for (POStore st : mapStores) { st.setInputs(null); st.setParentPlan(null); } for (POStore st : reduceStores) { st.setInputs(null); st.setParentPlan(null); } conf.set(PIG_MAP_STORES, ObjectSerializer.serialize(mapStores)); conf.set(PIG_REDUCE_STORES, ObjectSerializer.serialize(reduceStores)); } String tmp; long maxCombinedSplitSize = 0; if (!mro.combineSmallSplits() || pigContext.getProperties().getProperty("pig.splitCombination", "true").equals("false")) conf.setBoolean("pig.noSplitCombination", true); else if ((tmp = pigContext.getProperties().getProperty("pig.maxCombinedSplitSize", null)) != null) { try { maxCombinedSplitSize = Long.parseLong(tmp); } catch (NumberFormatException e) { log.warn( "Invalid numeric format for pig.maxCombinedSplitSize; use the default maximum combined split size"); } } if (maxCombinedSplitSize > 0) conf.setLong("pig.maxCombinedSplitSize", maxCombinedSplitSize); // It's a hack to set distributed cache file for hadoop 23. Once MiniMRCluster do not require local // jar on fixed location, this can be removed if (pigContext.getExecType() == ExecType.MAPREDUCE) { String newfiles = conf.get("alternative.mapreduce.job.cache.files"); if (newfiles != null) { String files = conf.get(MRConfiguration.JOB_CACHE_FILES); conf.set(MRConfiguration.JOB_CACHE_FILES, files == null ? newfiles.toString() : files + "," + newfiles); } } // Serialize the UDF specific context info. UDFContext.getUDFContext().serialize(conf); Job cjob = new Job(new JobConf(conf), new ArrayList<Job>()); jobStoreMap.put(cjob, new Pair<List<POStore>, Path>(storeLocations, tmpLocation)); return cjob; } catch (JobCreationException jce) { throw jce; } catch (Exception e) { int errCode = 2017; String msg = "Internal error creating job configuration."; throw new JobCreationException(msg, errCode, PigException.BUG, e); } }
From source file:com.gdo.servlet.RpcWrapper.java
/** * Adds status info to XML answer./*w w w .ja v a 2s. co m*/ * * @param writer * the XML answer writer. * @param status * the status to add. */ private void addStatus(XmlStringWriter writer, Result status) throws IOException { // if status null (on iterator or stencil) if (status == null) { writer.startElement("status"); writer.writeAttribute("level", Byte.toString(CommandStatus.SUCCESS)); writer.endElement("status"); return; } // writes status writer.startElement("status"); writer.writeAttribute("level", Byte.toString(status.getStatus())); for (CommandStatus.ResultInfo comp : status.getInfos(CommandStatus.SUCCESS)) { if (comp != null) { writer.startElement("ok"); writer.writeAttribute("cmdName", comp.getPrefix()); writer.writeAttribute("index", comp.getIndex()); if (comp.getValue() != null) { writer.writeCDATA(comp.getValue().toString()); } writer.endElement("ok"); } } for (CommandStatus.ResultInfo comp : status.getInfos(CommandStatus.WARNING)) { if (comp != null) { writer.startElement("warn"); writer.writeAttribute("cmdName", comp.getPrefix()); writer.writeAttribute("index", comp.getIndex()); if (comp.getValue() != null) { writer.writeCDATA(comp.getValue().toString()); } writer.endElement("warn"); } } for (CommandStatus.ResultInfo comp : status.getInfos(CommandStatus.ERROR)) { if (comp != null) { writer.startElement("error"); writer.writeAttribute("cmdName", comp.getPrefix()); writer.writeAttribute("index", comp.getIndex()); if (comp.getValue() != null) { writer.writeCDATA(comp.getValue().toString()); } writer.endElement("error"); } } writer.endElement("status"); }
From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java
public void rebootNode(byte cellId, int nodeId) throws MgmtException, ConnectException, PermissionException { ////from w w w .j a v a 2s. c om // We are inconsistently using node nomenclature // sometimes nodeids are 101-116 and sometime they're // 0-15. // if (nodeId < 100) nodeId += 101; if (!loggedIn()) throw new PermissionException(); HCNode node = getNode(cellId, nodeId); Object[] params = { Long.toString(_sessionId), Byte.toString(cellId), Integer.toString(nodeId) }; this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_REBOOT_NODE, params, "rebootNode"); node.reboot(BigInteger.valueOf(0)); }
From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java
public void rebootCell(HCCell cell, boolean _switches, boolean _sp) throws MgmtException, ConnectException, AdmException, PermissionException { if (!loggedIn()) throw new PermissionException(); BigInteger switches;/*from w ww .j ava2 s .c o m*/ BigInteger sp; String msg = AdminResourcesConstants.MSG_KEY_REBOOT; if (_switches) { switches = BigInteger.valueOf(0); msg = AdminResourcesConstants.MSG_KEY_REBOOT_SWITCH; } else { switches = BigInteger.valueOf(1); } if (_sp) { sp = BigInteger.valueOf(0); msg = (_switches ? AdminResourcesConstants.MSG_KEY_REBOOT_ALL : AdminResourcesConstants.MSG_KEY_REBOOT_SERVICE_PROCESSOR); } else { sp = BigInteger.valueOf(1); } if (!_internalCall) { Object[] params = { Long.toString(this._sessionId), Byte.toString(cell.getCellId()) }; extLog(ExtLevel.EXT_INFO, msg, params, "rebootCell"); } _internalCall = false; cell.reboot(new StatusCallback(), switches, sp); }
From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java
/** * * @see com.sun.honeycomb.adm.client.AdminClient#powerOff(cell,boolean,boolean) *//*from w w w . ja va 2 s. c om*/ public int powerOff(HCCell cell, boolean _sp, boolean _useIpmi) throws MgmtException, ConnectException, PermissionException { if (!loggedIn()) throw new PermissionException(); BigInteger useIpmi; BigInteger sp; if (_useIpmi) { useIpmi = BigInteger.valueOf(0); } else { useIpmi = BigInteger.valueOf(1); } if (_sp) { sp = BigInteger.valueOf(0); } else { sp = BigInteger.valueOf(1); } Object[] params = { Long.toString(this._sessionId), Byte.toString(cell.getCellId()) }; String msgKey = AdminResourcesConstants.MSG_KEY_SHUTDOWN; if (_sp) { if (_useIpmi) { msgKey = AdminResourcesConstants.MSG_KEY_SHUTDOWN_ALL_IPMI; } else { msgKey = AdminResourcesConstants.MSG_KEY_SHUTDOWN_ALL; } } else if (_useIpmi) { msgKey = AdminResourcesConstants.MSG_KEY_SHUTDOWN_IPMI; } this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_SHUTDOWN, params, "powerOff"); BigInteger result = cell.powerOff(new StatusCallback(), useIpmi, sp); return result.intValue(); }
From source file:com.sonymobile.android.media.internal.ISOBMFFParser.java
protected boolean parseBox(BoxHeader header) { if (header == null) { return false; }//from ww w . j av a2 s . c om mCurrentBoxSequence.add(header); if (LOGS_ENABLED) Log.v(TAG, "parse box " + ccruof(header.boxType) + " with size " + header.boxDataSize); boolean parseOK = true; long boxEndOffset = mCurrentOffset + header.boxDataSize; if (header.boxType == BOX_ID_FTYP) { } else if (header.boxType == BOX_ID_MOOV) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } // Merge tracks from moov and mfra if (mMfraTracks != null) { int numTracks = mTracks.size(); int numMfraTracks = mMfraTracks.size(); if (numMfraTracks > 0) { for (int i = 0; i < numTracks; i++) { IsoTrack track = (IsoTrack) mTracks.get(i); for (int j = 0; j < numMfraTracks; j++) { IsoTrack t = mMfraTracks.get(j); if (t.getTrackId() == track.getTrackId()) { track.setTfraList(t.getTfraList()); mMfraTracks.remove(j); break; } } } } mMfraTracks = null; } // Check for unsupported tracks int numTracks = mTracks.size(); if (LOGS_ENABLED) Log.v(TAG, numTracks + " tracks, " + "Video track " + getSelectedTrackIndex(TrackType.VIDEO) + " Audio track " + getSelectedTrackIndex(TrackType.AUDIO) + " Subtitle track " + getSelectedTrackIndex(TrackType.SUBTITLE)); for (int i = 0; i < numTracks; i++) { IsoTrack track = (IsoTrack) mTracks.get(i); if (track.getMediaFormat() == null) { if (LOGS_ENABLED) Log.v(TAG, "Track " + i + " is unhandled, type " + track.getTrackType()); track.setTrackType(TrackType.UNKNOWN); } else { if (LOGS_ENABLED) Log.v(TAG, "Track " + i + " of type " + track.getTrackType() + " is OK"); track.setTrackIndex(i); } } } else if (header.boxType == BOX_ID_MVHD) { parseOK = parseMvhd(header); } else if (header.boxType == BOX_ID_TRAK) { mIsParsingTrack = true; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } if (mParseODSMData) { if (!parseODSMData(mCurrentTrack)) { if (LOGS_ENABLED) Log.e(TAG, "Error while parsing ODSM track"); mCurrentBoxSequence.removeLast(); return false; } mParseODSMData = false; } mIsParsingTrack = false; } else if (header.boxType == BOX_ID_TKHD) { parseOK = readTkhd(header); } else if (header.boxType == BOX_ID_MDIA) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_MDHD) { parseOK = parseMdhd(header); } else if (header.boxType == BOX_ID_HDLR) { parseOK = parseHdlr(header); } else if (header.boxType == BOX_ID_MINF) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } if (parseOK) { if (mCurrentTrack.getTrackType() == TrackType.AUDIO && mCurrentAudioTrack == null) { if (LOGS_ENABLED) Log.v(TAG, "Setting audio track to " + mCurrentTrack.getTrackId()); mCurrentAudioTrack = mCurrentTrack; } else if (mCurrentTrack.getTrackType() == TrackType.VIDEO && mCurrentVideoTrack == null) { if (LOGS_ENABLED) Log.v(TAG, "Setting video track to " + mCurrentTrack.getTrackId()); mCurrentVideoTrack = mCurrentTrack; } } else { if (LOGS_ENABLED) Log.e(TAG, "Error parsing minf boxes"); } } else if (header.boxType == BOX_ID_STBL) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } if (parseOK) { IsoTrack currentTrack = (IsoTrack) mTracks.get(mTracks.size() - 1); SampleTable sampleTable = currentTrack.getSampleTable(); sampleTable.setTimescale(currentTrack.getTimeScale()); if (sampleTable.calculateSampleCountAndDuration() == false) { if (LOGS_ENABLED) Log.w(TAG, "Error while calculating sample count and duration"); } int sampleCount = sampleTable.getSampleCount(); if (sampleCount > 0) { mHasSampleTable = true; } long trackDurationUs = currentTrack.getDurationUs(); if (trackDurationUs > 0) { float frameRate = (sampleCount * 1000000.0f / trackDurationUs); mCurrentTrack.getMetaData().addValue(KEY_FRAME_RATE, frameRate); } else { mCurrentTrack.getMetaData().addValue(KEY_FRAME_RATE, 0f); } } } else if (header.boxType == BOX_ID_STSD) { // skip 4 for version and flags // skip 4 for entry_count mCurrentOffset += 8; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } if (mCurrentTrack.getMediaFormat() == null) { if (LOGS_ENABLED) Log.w(TAG, "Error parsing handler in 'stsd' box"); mCurrentTrack.setTrackType(TrackType.UNKNOWN); } } else if (header.boxType == BOX_ID_AVC1 || header.boxType == BOX_ID_AVC3) { byte[] data = new byte[78]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "Error while parsing 'avc1' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentMediaFormat = new MediaFormat(); parseVisualSampleEntry(data); mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.AVC); // TODO: Update this when we add support for nalSize other than 4 mCurrentMediaFormat.setInteger("nal-size", 4); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.AVC); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_AVCC) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "Error while parsing 'avcc' box", e); mCurrentBoxSequence.removeLast(); return false; } AvccData avccData = parseAvcc(data); if (avccData == null) { return false; } ByteBuffer csd0 = ByteBuffer.wrap(avccData.spsBuffer.array()); ByteBuffer csd1 = ByteBuffer.wrap(avccData.ppsBuffer.array()); mCurrentMediaFormat.setByteBuffer("csd-0", csd0); mCurrentMediaFormat.setByteBuffer("csd-1", csd1); mCurrentMediaFormat.setInteger("nal-length-size", mNALLengthSize); parseSPS(avccData.spsBuffer.array()); } else if (header.boxType == BOX_ID_STTS) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'stts' box", e); } mCurrentTrack.getSampleTable().setSttsData(data); } else if (header.boxType == BOX_ID_STSZ) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'stsz' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentTrack.getSampleTable().setStszData(data); } else if (header.boxType == BOX_ID_CTTS) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'ctts' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentTrack.getSampleTable().setCttsData(data); } else if (header.boxType == BOX_ID_STSC) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'stsc' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentTrack.getSampleTable().setStscData(data); } else if (header.boxType == BOX_ID_STSS) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'stss' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentTrack.getSampleTable().setStssData(data); } else if (header.boxType == BOX_ID_STCO) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'stco' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentTrack.getSampleTable().setStcoData(data); } else if (header.boxType == BOX_ID_CO64) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'co64' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentTrack.getSampleTable().setCo64Data(data); } else if (header.boxType == BOX_ID_MP4V) { byte[] data = new byte[78]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'mp4v' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentMediaFormat = new MediaFormat(); // mp4v is a type of VisualSampleEntry parseVisualSampleEntry(data); mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.MPEG4_VISUAL); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.MPEG4_VISUAL); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_MP4A) { byte[] data = new byte[28]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'mp4a' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentMediaFormat = new MediaFormat(); parseAudioSampleEntry(data); mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.AAC); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.AAC); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_ESDS) { // skip 4 for version and flags mCurrentOffset += 4; byte[] data = new byte[(int) header.boxDataSize - 4]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'esds' box", e); mCurrentBoxSequence.removeLast(); return false; } parseOK = parseESDS(data); } else if (header.boxType == BOX_ID_STPP) { mCurrentOffset += header.boxDataSize; mCurrentMediaFormat = new MediaFormat(); mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.TTML); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.TTML); mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_MVEX) { if (LOGS_ENABLED) Log.v(TAG, "found 'mvex', setting fragmented to true"); mIsFragmented = true; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_MEHD) { int versionFlags = 0; try { versionFlags = mDataSource.readInt(); int version = (versionFlags >> 24) & 0xFF; long durationTicks = 0; if (version == 1) { durationTicks = mDataSource.readLong(); } else { durationTicks = mDataSource.readInt(); } addMetaDataValue(KEY_DURATION, durationTicks * 1000 / mFileTimescale); } catch (EOFException e) { if (LOGS_ENABLED) Log.e(TAG, "EOFException while parsing 'mvex' box", e); mCurrentBoxSequence.removeLast(); return false; } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'mehd' box", e); mCurrentBoxSequence.removeLast(); return false; } } else if (header.boxType == BOX_ID_TREX) { try { Trex newTrex = new Trex(); mDataSource.skipBytes(4); // version and flags int trackId = mDataSource.readInt(); mDataSource.skipBytes(4); // Skip Default Sample Description Index newTrex.defaultSampleDuration = mDataSource.readInt(); newTrex.defaultSampleSize = mDataSource.readInt(); mDataSource.skipBytes(4); // Skip Default Sample Flags IsoTrack track = null; int numTracks = mTracks.size(); for (int i = 0; i < numTracks; i++) { IsoTrack t = (IsoTrack) (mTracks.get(i)); if (t.getTrackId() == trackId) { track = t; break; } } if (track == null) { track = (IsoTrack) createTrack(); track.setTrackId(trackId); mTracks.add(track); } if (track != null) { track.setTrex(newTrex); } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'trex' box", e); mCurrentBoxSequence.removeLast(); return false; } } else if (header.boxType == BOX_ID_MOOF) { if (mFirstMoofOffset == -1) { mIsFragmented = true; mInitDone = true; mFirstMoofOffset = header.startOffset; mCurrentBoxSequence.removeLast(); return true; } mCurrentMoofOffset = header.startOffset; mMoofDataSize = 0; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_TRAF) { mParsedSencData = false; mCurrentTrackFragment = new Traf(); mPrevTrunDataSize = 0; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_TFHD) { parseOK = parseTfhd(header); } else if (header.boxType == BOX_ID_TRUN) { parseOK = parseTrun(header); } else if (header.boxType == BOX_ID_MFRA) { if (!mFoundMfra) { mMfraTracks = new ArrayList<ISOBMFFParser.IsoTrack>(2); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mFoundMfra = true; } } else if (header.boxType == BOX_ID_TFRA) { parseOK = parseTfra(header); } else if (header.boxType == BOX_ID_ENCA) { byte[] data = new byte[28]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'enca' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentMediaFormat = new MediaFormat(); parseAudioSampleEntry(data); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_ENCV) { byte[] data = new byte[78]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'encv' box", e); mCurrentBoxSequence.removeLast(); return false; } mCurrentMediaFormat = new MediaFormat(); parseVisualSampleEntry(data); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_FRMA) { try { int dataFormat = mDataSource.readInt(); if (dataFormat == BOX_ID_AVC1) { mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.AVC); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.AVC); } else if (dataFormat == BOX_ID_HVC1) { mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.HEVC); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.HEVC); } else if (dataFormat == BOX_ID_MP4V) { mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.MPEG4_VISUAL); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.MPEG4_VISUAL); } else if (dataFormat == BOX_ID_MP4A) { mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.AAC); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.AAC); } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "Exception while parsing 'frma' box", e); mCurrentBoxSequence.removeLast(); return false; } } else if (header.boxType == BOX_ID_SCHM) { try { int versionFlags = mDataSource.readInt(); mDataSource.skipBytes(8); // scheme_type and scheme_version if ((versionFlags & 0x01) != 0) { // TODO read scheme_uri if we're interested // byte[] data = new byte[(int)header.boxDataSize - 12]; // mDataSource.read(data); mDataSource.skipBytes(header.boxDataSize - 12); } } catch (EOFException e) { if (LOGS_ENABLED) Log.e(TAG, "Error parsing 'schm' box", e); mCurrentBoxSequence.removeLast(); parseOK = false; } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "Error parsing 'schm' box", e); mCurrentBoxSequence.removeLast(); parseOK = false; } } else if (header.boxType == BOX_ID_SCHI) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_EDTS) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_ELST) { parseOK = parseElst(header); } else if (header.boxType == BOX_ID_PSSH) { parseOK = parsePsshData(header); } else if (header.boxType == BOX_ID_TENC) { try { // Skip version, flags and algorithm id mDataSource.skipBytes(7); int ivSize = mDataSource.readByte(); byte[] kID = new byte[16]; mDataSource.read(kID); mCurrentTrack.setDefaultEncryptionData(ivSize, kID); parseOK = true; } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'tenc' box", e); parseOK = false; } } else if (header.boxType == BOX_ID_SENC) { if (mCurrentMoofTrackId == mCurrentTrackId && !mSkipInsertSamples && !mParsedSencData) { mParsedSencData = true; try { int versionFlags = mDataSource.readInt(); int sampleCount = mDataSource.readInt(); ArrayList<CryptoInfo> cryptoInfos = new ArrayList<CryptoInfo>(sampleCount); for (int i = 0; i < sampleCount; i++) { CryptoInfo info = new CryptoInfo(); info.mode = MediaCodec.CRYPTO_MODE_AES_CTR; info.iv = new byte[16]; if (mCurrentTrack.mDefaultIVSize == 16) { mDataSource.read(info.iv); } else { // pad IV data to 128 bits byte[] iv = new byte[8]; mDataSource.read(iv); System.arraycopy(iv, 0, info.iv, 0, 8); } if ((versionFlags & 0x00000002) > 0) { short subSampleCount = mDataSource.readShort(); info.numSubSamples = subSampleCount; info.numBytesOfClearData = new int[subSampleCount]; info.numBytesOfEncryptedData = new int[subSampleCount]; for (int j = 0; j < subSampleCount; j++) { info.numBytesOfClearData[j] = mDataSource.readShort(); info.numBytesOfEncryptedData[j] = mDataSource.readInt(); } } else { info.numSubSamples = 1; info.numBytesOfClearData = new int[1]; info.numBytesOfClearData[0] = 0; info.numBytesOfEncryptedData = new int[1]; info.numBytesOfEncryptedData[0] = -1; } if (info.numBytesOfClearData[0] == 0 && mCurrentTrack.getTrackType() == TrackType.VIDEO) { info.iv[15] = (byte) mNALLengthSize; } cryptoInfos.add(info); } mCurrentTrack.addCryptoInfos(cryptoInfos); } catch (EOFException e) { if (LOGS_ENABLED) Log.e(TAG, "Error parsing 'senc' box", e); mCurrentBoxSequence.removeLast(); parseOK = false; } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "Error parsing 'senc' box", e); mCurrentBoxSequence.removeLast(); parseOK = false; } } } else if (header.boxType == BOX_ID_SINF) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_HVC1 || header.boxType == BOX_ID_HEV1) { byte[] data = new byte[78]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'hvc1' box", e); return false; } mCurrentMediaFormat = new MediaFormat(); mCurrentMediaFormat.setString(MediaFormat.KEY_MIME, MimeType.HEVC); mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.HEVC); parseVisualSampleEntry(data); while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentTrack.addSampleDescriptionEntry(mCurrentMediaFormat); } else if (header.boxType == BOX_ID_HVCC) { byte[] data = new byte[(int) header.boxDataSize]; try { if (mDataSource.readAt(mCurrentOffset, data, data.length) != data.length) { mCurrentBoxSequence.removeLast(); return false; } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException while parsing 'hvcc' box", e); return false; } byte[] hvccData = parseHvcc(data); if (hvccData == null) { return false; } ByteBuffer csd0 = ByteBuffer.wrap(hvccData); mCurrentMediaFormat.setByteBuffer("csd-0", csd0); mCurrentMediaFormat.setInteger("nal-length-size", mNALLengthSize); } else if (header.boxType == BOX_ID_UDTA) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_META) { mCurrentOffset += 4; // skip version and flags while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_ILST) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else if (header.boxType == BOX_ID_ATNAM) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_TITLE; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_ATALB) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_ALBUM; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_ATART) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_ARTIST; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_AART) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_ALBUM_ARTIST; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_ATDAY) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_YEAR; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_TRKN) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_TRACK_NUMBER; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_ATGEN || header.boxType == BOX_ID_GNRE) { mCurrentMetaDataKey = KEY_GENRE; if (boxIsUnder(BOX_ID_ILST)) { while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } } else { // 3gpp metadata value try { mDataSource.skipBytes(4); // skip version and flags mDataSource.skipBytes(2); // skip language code byte[] buffer = new byte[(int) (header.boxDataSize - 6)]; mDataSource.read(buffer); String metaDataValue = null; if ((0xFF & buffer[0]) == 0xFF && (0xFF & buffer[1]) == 0xFE || (0xFF & buffer[0]) == 0xFE && (0xFF & buffer[1]) == 0xFF) { metaDataValue = new String(buffer, 0, buffer.length - 2, StandardCharsets.UTF_16); } else { metaDataValue = new String(buffer, 0, buffer.length - 1, StandardCharsets.UTF_8); } addMetaDataValue(mCurrentMetaDataKey, metaDataValue); } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException parsing 'gnre' box", e); parseOK = false; } } mCurrentMetaDataKey = null; } else if (header.boxType == BOX_ID_CPIL) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_COMPILATION; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_ATWRT) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_WRITER; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_DISK) { if (boxIsUnder(BOX_ID_ILST)) { mCurrentMetaDataKey = KEY_DISC_NUMBER; while (mCurrentOffset < boxEndOffset && parseOK) { BoxHeader nextBoxHeader = getNextBoxHeader(); parseOK = parseBox(nextBoxHeader); } mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_DATA) { parseOK = parseDataBox(header); } else if (header.boxType == BOX_ID_ID32) { parseOK = parseID3(header); } else if (header.boxType == BOX_ID_TITL) { if (!mMetaDataValues.containsKey(KEY_TITLE)) { mCurrentMetaDataKey = KEY_TITLE; parseOK = parse3GPPMetaDataString(header); mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_PERF) { if (!mMetaDataValues.containsKey(KEY_ARTIST)) { mCurrentMetaDataKey = KEY_ARTIST; parseOK = parse3GPPMetaDataString(header); mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_AUTH) { if (!mMetaDataValues.containsKey(KEY_AUTHOR)) { mCurrentMetaDataKey = KEY_AUTHOR; parseOK = parse3GPPMetaDataString(header); mCurrentMetaDataKey = null; } } else if (header.boxType == BOX_ID_ALBM) { if (!mMetaDataValues.containsKey(KEY_ALBUM)) { try { mDataSource.skipBytes(4); // skip version and flags mDataSource.skipBytes(2); // skip language code byte[] buffer = new byte[(int) (header.boxDataSize - 6)]; mDataSource.read(buffer); String metaDataValue = null; if ((0xFF & buffer[0]) == 0xFF && (0xFF & buffer[1]) == 0xFE) { if (buffer[buffer.length - 3] == 0 && buffer[buffer.length - 2] == 0) { if (!mMetaDataValues.containsKey(KEY_TRACK_NUMBER)) { String trackNumber = Byte.toString(buffer[buffer.length - 1]); addMetaDataValue(KEY_TRACK_NUMBER, trackNumber); } metaDataValue = new String(buffer, 0, buffer.length - 3, StandardCharsets.UTF_16); } else { metaDataValue = new String(buffer, StandardCharsets.UTF_16); } } else if ((0xFF & buffer[0]) == 0xFE && (0xFF & buffer[1]) == 0xFF) { if (buffer[buffer.length - 3] == 0 && buffer[buffer.length - 2] == 0) { if (!mMetaDataValues.containsKey(KEY_TRACK_NUMBER)) { String trackNumber = Byte.toString(buffer[buffer.length - 1]); addMetaDataValue(KEY_TRACK_NUMBER, trackNumber); } metaDataValue = new String(buffer, 0, buffer.length - 3, StandardCharsets.UTF_16); } else { metaDataValue = new String(buffer, 0, buffer.length - 2, StandardCharsets.UTF_16); } } else { if (buffer[buffer.length - 2] == 0) { if (!mMetaDataValues.containsKey(KEY_TRACK_NUMBER)) { String trackNumber = Byte.toString(buffer[buffer.length - 1]); addMetaDataValue(KEY_TRACK_NUMBER, trackNumber); } metaDataValue = new String(buffer, 0, buffer.length - 2, StandardCharsets.UTF_8); } else { metaDataValue = new String(buffer, 0, buffer.length - 1, StandardCharsets.UTF_8); } } addMetaDataValue(KEY_ALBUM, metaDataValue); } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException parsing 'albm' box", e); parseOK = false; } } } else if (header.boxType == BOX_ID_YRRC) { try { mDataSource.skipBytes(4); // skip version and flags if (header.boxDataSize > 6) { // This should be a 16 bit int according to spec, but some // files have this as a string mDataSource.skipBytes(2); // skip language code byte[] buffer = new byte[(int) (header.boxDataSize - 6)]; mDataSource.read(buffer); String metaDataValue = null; if ((0xFF & buffer[0]) == 0xFF && (0xFF & buffer[1]) == 0xFE || (0xFF & buffer[0]) == 0xFE && (0xFF & buffer[1]) == 0xFF) { metaDataValue = new String(buffer, 0, buffer.length - 2, StandardCharsets.UTF_16); } else { metaDataValue = new String(buffer, 0, buffer.length - 1, StandardCharsets.UTF_8); } addMetaDataValue(KEY_YEAR, metaDataValue); } else { int year = mDataSource.readShort(); String metaDataValue = Integer.toString(year); addMetaDataValue(KEY_YEAR, metaDataValue); } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "IOException parsing 'yrrc' box", e); parseOK = false; } } else if (header.boxType == BOX_ID_MDAT) { if (mTracks.size() > 0 && !mIsFragmented) { mInitDone = true; } else if (mIsFragmented && mFirstMoofOffset != -1) { mInitDone = true; } else { mMdatFound = true; } } else { long skipSize = header.boxDataSize; try { while (skipSize > Integer.MAX_VALUE) { mDataSource.skipBytes(Integer.MAX_VALUE); skipSize -= Integer.MAX_VALUE; } if (skipSize > 0) { mDataSource.skipBytes(skipSize); } } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "could not skip box"); mCurrentBoxSequence.removeLast(); parseOK = false; } } mCurrentOffset = boxEndOffset; mCurrentBoxSequence.removeLast(); return parseOK; }
From source file:edu.stanford.muse.util.Util.java
/** * converts an object to a string->string map by converting all its fields * (fields may be non-public/* w ww . j a v a 2 s . co m*/ * if running without security manager). expand=true expands collections * (array, list, map) */ public static Map<String, String> convertObjectToMap(Object o, boolean expand) { Map<String, String> map = new LinkedHashMap<String, String>(); if (o == null) return map; Class c = o.getClass(); try { // generate a string to string map of the fields Field f[] = c.getDeclaredFields(); for (int i = 0; i < f.length; i++) { boolean acc = f[i].isAccessible(); if (!acc) f[i].setAccessible(true); // ok to do in absence of a security manager Class t = f[i].getType(); String name = f[i].getName(); if (name.indexOf("$") >= 0) // outer class, skip" + continue; if (t == double.class) map.put(name, Double.toString(f[i].getDouble(o))); else if (t == float.class) map.put(name, Float.toString(f[i].getFloat(o))); else if (t == int.class) map.put(name, Integer.toString(f[i].getInt(o))); else if (t == long.class) map.put(name, Long.toString(f[i].getLong(o))); else if (t == char.class) map.put(name, f[i].getChar(o) + "(" + Integer.toString(f[i].getChar(o)) + ")"); else if (t == short.class) map.put(name, Short.toString(f[i].getShort(o))); else if (t == byte.class) map.put(name, Byte.toString(f[i].getByte(o))); else if (t == boolean.class) map.put(name, Boolean.toString(f[i].getBoolean(o))); else { // field is of object type Object val = f[i].get(o); // o.f[i]'s type is t, value is // val if (val == null) map.put(name, "null"); else { Class valClass = val.getClass(); if (valClass.isArray()) { if (expand) for (int x = 0; x < Array.getLength(val); x++) map.put(name + "[" + x + "]", Array.get(val, x) + ""); } else if (java.util.Map.class.isAssignableFrom(valClass)) // could // also // check // t, // but // val.getClass // is // more // specific { Map m = (Map) f[i].get(o); if (expand) for (Object x : m.keySet()) map.put(name + "." + x, m.get(x) + ""); } // could also check t, but val.getClass is more specific else if (java.util.Collection.class.isAssignableFrom(valClass)) { Collection c1 = (Collection) f[i].get(o); if (expand) { int count = 0; for (Object o1 : c1) map.put(name + "(" + count++ + ")", o1 + ""); // use // () // instead // of // [] // to // distinguish // from // arrays } } else map.put(name, "[" + val.toString() + "]"); } } if (!acc) f[i].setAccessible(false); } } catch (Throwable e) { Util.print_exception(e); } return map; }
From source file:forseti.admon.JAdmCFDDlg.java
public void GenerarXMLCE(HttpServletRequest request, HttpServletResponse response, int ano, int mes) throws ServletException, IOException { int errores = 0, alertas = 0; String nomArchFech;//ww w . ja v a 2s . co m if (mes < 10) nomArchFech = "-" + ano + "-0" + mes; else nomArchFech = "-" + ano + "-" + mes; String nomArch = "/usr/local/forseti/emp/" + getSesion(request).getBDCompania() + "/CE/"; JAdmVariablesSet var = new JAdmVariablesSet(request); var.m_Where = "ID_Variable = 'RFC'"; var.Open(); String rfcfmt = JUtil.fco(JUtil.frfc(var.getAbsRow(0).getVAlfanumerico())); if (getSesion(request).getSesion("ADM_CFDI").getEspecial().equals("CECAT")) { FileWriter filewri = new FileWriter(nomArch + "CECAT" + nomArchFech + ".log"); PrintWriter pw = new PrintWriter(filewri); try { JContCatalogoCESet cat = new JContCatalogoCESet(request); cat.m_OrderBy = "Cuenta ASC"; cat.Open(); if (rfcfmt.equals("") || rfcfmt.length() > 13 || rfcfmt.length() < 12) { pw.println("ERROR CATALOGO: RFC Mal Formado: " + rfcfmt + "\n"); pw.flush(); errores++; } Namespace ns = Namespace.getNamespace("www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas"); Element Catalogo = new Element("Catalogo", ns); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Catalogo.setAttribute("schemaLocation", "www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas/CatalogoCuentas_1_1.xsd", xsi); Catalogo.setAttribute("Version", "1.1"); Catalogo.setAttribute("RFC", rfcfmt); Catalogo.setAttribute("Mes", (mes < 10 ? "0" + Integer.toString(mes) : Integer.toString(mes))); Catalogo.setAttribute("Anio", Integer.toString(ano)); Document DocCatalogo = new Document(); DocCatalogo.setRootElement(Catalogo); for (int i = 0; i < cat.getNumRows(); i++) { Element Ctas = new Element("Ctas", ns); if (cat.getAbsRow(i).getCE_CodAgrup().equals("")) { pw.println("ERROR CATALOGO: Codigo Agrupador de Cuenta " + cat.getAbsRow(i).getCuenta() + " Inexistente\n"); pw.flush(); errores++; } Ctas.setAttribute("CodAgrup", cat.getAbsRow(i).getCE_CodAgrup()); Ctas.setAttribute("NumCta", cat.getAbsRow(i).getCuenta()); Ctas.setAttribute("Desc", cat.getAbsRow(i).getNombre()); if (cat.getAbsRow(i).getNivel() > 1) Ctas.setAttribute("SubCtaDe", cat.getAbsRow(i).getSubCuentaDe()); Ctas.setAttribute("Nivel", Integer.toString(cat.getAbsRow(i).getNivel())); Ctas.setAttribute("Natur", cat.getAbsRow(i).getCE_Natur()); Catalogo.addContent(Ctas); } Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); FileWriter writer = new FileWriter(nomArch + "CECAT" + nomArchFech + ".xml"); xmlOutputter.output(DocCatalogo, writer); writer.close(); pw.println("-------------------------------------------------------------------------------"); pw.println(" ERRORES: " + errores + " ALERTAS: " + alertas); pw.flush(); String str = "select * from sp_cont_ce_generar('" + ano + "','" + mes + "','" + errores + "','" + alertas + "','CAT') as ( err integer, res varchar, clave varchar ) "; JRetFuncBas rfb = new JRetFuncBas(); doCallStoredProcedure(request, response, str, rfb); RDP("CEF", getSesion(request).getConBD(), (rfb.getIdmensaje() == 0 ? "OK" : (rfb.getIdmensaje() == 4 ? "AL" : "ER")), getSesion(request).getID_Usuario(), "ADM_CFDI_GCEXML", "ACFD|" + rfb.getClaveret() + "|||", rfb.getRes()); irApag("/forsetiweb/administracion/adm_cfd_dlg_cegen.jsp", request, response); } finally { pw.close(); filewri.close(); } } else if (getSesion(request).getSesion("ADM_CFDI").getEspecial().equals("CEBAL")) { FileWriter filewri = new FileWriter(nomArch + "CEBAL" + nomArchFech + ".log"); PrintWriter pw = new PrintWriter(filewri); try { JContBalanzaCESet bal = new JContBalanzaCESet(request); bal.m_Where = "Mes = '" + mes + "' and Ano = '" + ano + "'"; bal.m_OrderBy = "Cuenta ASC"; bal.Open(); if (rfcfmt.equals("") || rfcfmt.length() > 13 || rfcfmt.length() < 12) { pw.println("ERROR BALANZA: RFC Mal Formado: " + rfcfmt + "\n"); pw.flush(); errores++; } Namespace ns = Namespace .getNamespace("www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion"); Element Balanza = new Element("Balanza", ns); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Balanza.setAttribute("schemaLocation", "www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion/BalanzaComprobacion_1_1.xsd", xsi); Balanza.setAttribute("Version", "1.1"); Balanza.setAttribute("RFC", rfcfmt); Balanza.setAttribute("Mes", (mes < 10 ? "0" + Integer.toString(mes) : Integer.toString(mes))); Balanza.setAttribute("Anio", Integer.toString(ano)); Balanza.setAttribute("TipoEnvio", (request.getParameter("tipoenvio") != null ? p(request.getParameter("tipoenvio")) : "N")); Document DocBalanza = new Document(); DocBalanza.setRootElement(Balanza); for (int i = 0; i < bal.getNumRows(); i++) { Element Ctas = new Element("Ctas", ns); Ctas.setAttribute("NumCta", bal.getAbsRow(i).getCuenta()); Ctas.setAttribute("SaldoIni", JUtil.Converts(bal.getAbsRow(i).getInicial(), "", ".", 2, false)); Ctas.setAttribute("Debe", JUtil.Converts(bal.getAbsRow(i).getCargos(), "", ".", 2, false)); Ctas.setAttribute("Haber", JUtil.Converts(bal.getAbsRow(i).getAbonos(), "", ".", 2, false)); Ctas.setAttribute("SaldoFin", JUtil.Converts(bal.getAbsRow(i).getFinal(), "", ".", 2, false)); Balanza.addContent(Ctas); } Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); FileWriter writer = new FileWriter(nomArch + "CEBAL" + nomArchFech + ".xml"); xmlOutputter.output(DocBalanza, writer); writer.close(); pw.println("-------------------------------------------------------------------------------"); pw.println(" ERRORES: " + errores + " ALERTAS: " + alertas); pw.flush(); String str = "select * from sp_cont_ce_generar('" + ano + "','" + mes + "','" + errores + "','" + alertas + "','BAL') as ( err integer, res varchar, clave varchar ) "; JRetFuncBas rfb = new JRetFuncBas(); doCallStoredProcedure(request, response, str, rfb); RDP("CEF", getSesion(request).getConBD(), (rfb.getIdmensaje() == 0 ? "OK" : (rfb.getIdmensaje() == 4 ? "AL" : "ER")), getSesion(request).getID_Usuario(), "ADM_CFDI_GCEXML", "ACFD|" + rfb.getClaveret() + "|||", rfb.getRes()); irApag("/forsetiweb/administracion/adm_cfd_dlg_cegen.jsp", request, response); } finally { pw.close(); filewri.close(); } } else if (getSesion(request).getSesion("ADM_CFDI").getEspecial().equals("CEPOL")) { FileWriter filewri = new FileWriter(nomArch + "CEPOL" + nomArchFech + ".log"); PrintWriter pw = new PrintWriter(filewri); try { if (rfcfmt.equals("") || rfcfmt.length() > 13 || rfcfmt.length() < 12) { pw.println("ERROR POLIZAS: RFC Mal Formado: " + rfcfmt + "\n"); pw.flush(); errores++; } //////////////////////////////////////////// Namespace ns = Namespace.getNamespace("www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo"); Element Polizas = new Element("Polizas", ns); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Polizas.setAttribute("schemaLocation", "www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo/PolizasPeriodo_1_1.xsd", xsi); Polizas.setAttribute("Version", "1.1"); Polizas.setAttribute("RFC", rfcfmt); Polizas.setAttribute("Mes", (mes < 10 ? "0" + Integer.toString(mes) : Integer.toString(mes))); Polizas.setAttribute("Anio", Integer.toString(ano)); Polizas.setAttribute("TipoSolicitud", (request.getParameter("tiposolicitud") != null ? p(request.getParameter("tiposolicitud")) : "AF")); if (request.getParameter("numorden") != null && !request.getParameter("numorden").equals("")) Polizas.setAttribute("NumOrden", p(request.getParameter("numorden"))); if (request.getParameter("numtramite") != null && !request.getParameter("numtramite").equals("")) Polizas.setAttribute("NumTramite", p(request.getParameter("numtramite"))); Document DocPolizas = new Document(); DocPolizas.setRootElement(Polizas); JContPolizasCECabSet pol = new JContPolizasCECabSet(request); pol.m_Where = "date_part('Month',Fecha) = '" + mes + "' and date_part('Year',Fecha) = '" + ano + "' and Status <> 'C'"; pol.m_OrderBy = "Fecha ASC, ID ASC"; pol.Open(); for (int i = 0; i < pol.getNumRows(); i++) { Element Poliza = new Element("Poliza"); Poliza.setAttribute("Tipo", Byte.toString(pol.getAbsRow(i).getTipo())); Poliza.setAttribute("Num", pol.getAbsRow(i).getNum()); Poliza.setAttribute("Fecha", JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "yyyy-MM-dd")); Poliza.setAttribute("Concepto", pol.getAbsRow(i).getConcepto()); JContPolizasCEDetSet det = new JContPolizasCEDetSet(request); det.m_Where = "ID = '" + pol.getAbsRow(i).getID() + "'"; det.m_OrderBy = "Part ASC"; det.Open(); for (int t = 0; t < det.getNumRows(); t++) { Element Transaccion = new Element("Transaccion"); Transaccion.setAttribute("NumCta", det.getAbsRow(t).getCuenta()); Transaccion.setAttribute("Concepto", det.getAbsRow(t).getConcepto()); Transaccion.setAttribute("Debe", JUtil.Converts(det.getAbsRow(t).getDebe(), "", ".", 2, false)); Transaccion.setAttribute("Haber", JUtil.Converts(det.getAbsRow(t).getHaber(), "", ".", 2, false)); Transaccion.setAttribute("Moneda", det.getAbsRow(t).getMoneda()); Transaccion.setAttribute("TipCamb", JUtil.Converts(det.getAbsRow(t).getTC(), "", ".", 2, false)); JContPolizasDetalleCEChequesSet schq = new JContPolizasDetalleCEChequesSet(request); schq.m_Where = "ID_Pol = '" + det.getAbsRow(t).getID() + "' and ID_Part = '" + det.getAbsRow(t).getPart() + "'"; schq.Open(); for (int chq = 0; chq < schq.getNumRows(); chq++) { Element Cheque = new Element("Cheque"); if (!schq.getAbsRow(chq).getNum().matches("\\d+")) { pw.println("ALERTA CE CHEQUE: Numero de CHEQUE contiene caracteres Alfanumericos: " + schq.getAbsRow(chq).getNum()); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); alertas++; } Cheque.setAttribute("Num", schq.getAbsRow(chq).getNum()); Cheque.setAttribute("Banco", schq.getAbsRow(chq).getBanco()); if (!schq.getAbsRow(chq).getCtaOri().matches("\\d+")) { pw.println("ALERTA CE CHEQUE: Numero de CUENTA contiene caracteres Alfanumericos: " + schq.getAbsRow(chq).getCtaOri()); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); alertas++; } Cheque.setAttribute("CtaOri", schq.getAbsRow(chq).getCtaOri()); Cheque.setAttribute("Fecha", JUtil.obtFechaTxt(schq.getAbsRow(chq).getFecha(), "yyyy-MM-dd")); Cheque.setAttribute("Monto", JUtil.Converts(schq.getAbsRow(chq).getMonto(), "", ".", 2, false)); Cheque.setAttribute("Benef", schq.getAbsRow(chq).getBenef()); String rfc = schq.getAbsRow(chq).getRFC(); if (rfc.equals("") || rfc.length() > 13 || rfc.length() < 12) { pw.println("ERROR CE CHEQUE: RFC Mal Formado: " + rfc); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); errores++; } Cheque.setAttribute("RFC", rfc); Transaccion.addContent(Cheque); } JContPolizasDetalleCETransferenciasSet strn = new JContPolizasDetalleCETransferenciasSet( request); strn.m_Where = "ID_Pol = '" + det.getAbsRow(t).getID() + "' and ID_Part = '" + det.getAbsRow(t).getPart() + "'"; strn.Open(); for (int trn = 0; trn < strn.getNumRows(); trn++) { Element Transferencia = new Element("Transferencia"); if (!strn.getAbsRow(trn).getCtaOri().matches("\\d+")) { pw.println( "ALERTA CE TRANSFERENCIA: Numero de CUENTA ORIGEN contiene caracteres Alfanumericos: " + strn.getAbsRow(trn).getCtaOri()); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); alertas++; } Transferencia.setAttribute("CtaOri", strn.getAbsRow(trn).getCtaOri()); Transferencia.setAttribute("BancoOri", strn.getAbsRow(trn).getBancoOri()); Transferencia.setAttribute("Monto", JUtil.Converts(strn.getAbsRow(trn).getMonto(), "", ".", 2, false)); if (!strn.getAbsRow(trn).getCtaDest().matches("\\d+")) { pw.println( "ALERTA CE TRANSFERENCIA: Numero de CUENTA DESTINO contiene caracteres Alfanumericos: " + strn.getAbsRow(trn).getCtaOri()); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); alertas++; } Transferencia.setAttribute("CtaDest", strn.getAbsRow(trn).getCtaDest()); Transferencia.setAttribute("BancoDest", strn.getAbsRow(trn).getBancoDest()); Transferencia.setAttribute("Fecha", JUtil.obtFechaTxt(strn.getAbsRow(trn).getFecha(), "yyyy-MM-dd")); Transferencia.setAttribute("Benef", strn.getAbsRow(trn).getBenef()); String rfc = strn.getAbsRow(trn).getRFC(); if (rfc.equals("") || rfc.length() > 13 || rfc.length() < 12) { pw.println("ERROR CE TRANSFERENCIA: RFC Mal Formado: " + rfc); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); errores++; } Transferencia.setAttribute("RFC", rfc); Transaccion.addContent(Transferencia); } JContPolizasDetalleCEComprobantesSet sxml = new JContPolizasDetalleCEComprobantesSet( request); sxml.m_Where = "ID_Pol = '" + det.getAbsRow(t).getID() + "' and ID_Part = '" + det.getAbsRow(t).getPart() + "'"; sxml.Open(); for (int xml = 0; xml < sxml.getNumRows(); xml++) { Element Comprobante = new Element("Comprobante"); if (sxml.getAbsRow(xml).getUUID_CFDI().length() != 36) { pw.println("ERROR CE COMPROBANTE: UUID no valido: " + sxml.getAbsRow(xml).getUUID_CFDI()); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); alertas++; } else if (!sxml.getAbsRow(xml).getUUID_CFDI().matches( "[a-f0-9A-F]{8}-[a-f0-9A-F]{4}-[a-f0-9A-F]{4}-[a-f0-9A-F]{4}-[a-f0-9A-F]{12}")) { pw.println("ALERTA CE COMPROBANTE: UUID no parece ser valido: " + sxml.getAbsRow(xml).getUUID_CFDI()); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); alertas++; } Comprobante.setAttribute("UUID_CFDI", sxml.getAbsRow(xml).getUUID_CFDI()); Comprobante.setAttribute("Monto", JUtil.Converts(sxml.getAbsRow(xml).getMonto(), "", ".", 2, false)); String rfc = sxml.getAbsRow(xml).getRFC(); if (rfc.equals("") || rfc.length() > 13 || rfc.length() < 12) { pw.println("ERROR CE COMPROBANTE: RFC Mal Formado: " + rfc); pw.println("-- Pliza " + pol.getAbsRow(i).getNum() + " " + JUtil.obtFechaTxt(pol.getAbsRow(i).getFecha(), "dd/MMM/yyyy") + " " + pol.getAbsRow(i).getConcepto() + " Partida: " + det.getAbsRow(t).getPart() + "\n"); pw.flush(); errores++; } Comprobante.setAttribute("RFC", sxml.getAbsRow(xml).getRFC()); Transaccion.addContent(Comprobante); } Poliza.addContent(Transaccion); } Polizas.addContent(Poliza); } Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); FileWriter writer = new FileWriter(nomArch + "CEPOL" + nomArchFech + ".xml"); xmlOutputter.output(DocPolizas, writer); writer.close(); pw.println("-------------------------------------------------------------------------------"); pw.println(" ERRORES: " + errores + " ALERTAS: " + alertas); pw.flush(); String str = "select * from sp_cont_ce_generar('" + ano + "','" + mes + "','" + errores + "','" + alertas + "','POL') as ( err integer, res varchar, clave varchar ) "; JRetFuncBas rfb = new JRetFuncBas(); doCallStoredProcedure(request, response, str, rfb); RDP("CEF", getSesion(request).getConBD(), (rfb.getIdmensaje() == 0 ? "OK" : (rfb.getIdmensaje() == 4 ? "AL" : "ER")), getSesion(request).getID_Usuario(), "ADM_CFDI_GCEXML", "ACFD|" + rfb.getClaveret() + "|||", rfb.getRes()); irApag("/forsetiweb/administracion/adm_cfd_dlg_cegen.jsp", request, response); } finally { pw.close(); filewri.close(); } } }