Package com.sun.j3d.loaders.lw3d

Source Code of com.sun.j3d.loaders.lw3d.LWOBFileReader

/*     */ package com.sun.j3d.loaders.lw3d;
/*     */
/*     */ import com.sun.j3d.loaders.ParsingErrorException;
/*     */ import java.io.BufferedInputStream;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */ import java.net.URL;
/*     */
/*     */ class LWOBFileReader extends BufferedInputStream
/*     */ {
/*     */   static final int TRACE = 1;
/*     */   static final int VALUES = 2;
/*     */   static final int MISC = 4;
/*     */   static final int LINE_TRACE = 8;
/*     */   static final int NONE = 0;
/*     */   static final int EXCEPTION = 16;
/*     */   protected DebugOutput debugPrinter;
/*     */   protected String theFilename;
/*     */   protected int marker;
/*     */
/*     */   protected void debugOutputLn(int outputType, String theOutput)
/*     */   {
/*  73 */     if (theOutput.equals(""))
/*  74 */       this.debugPrinter.println(outputType, theOutput);
/*     */     else
/*  76 */       this.debugPrinter.println(outputType, getClass().getName() + "::" + theOutput);
/*     */   }
/*     */
/*     */   public String getToken()
/*     */     throws ParsingErrorException
/*     */   {
/*  84 */     byte[] tokenBuffer = new byte[4];
/*     */     try {
/*  86 */       int readResult = read(tokenBuffer, 0, 4);
/*  87 */       if (readResult == -1) {
/*  88 */         debugOutputLn(8, "no token - returning null");
/*  89 */         return null;
/*     */       }
/*  91 */       return new String(tokenBuffer);
/*     */     }
/*     */     catch (IOException e) {
/*  94 */       debugOutputLn(16, "getToken: " + e);
/*  95 */       throw new ParsingErrorException(e.getMessage());
/*     */     }
/*     */   }
/*     */
/*     */   public void skipLength(int amount)
/*     */     throws ParsingErrorException
/*     */   {
/*     */     try
/*     */     {
/* 106 */       skip(amount);
/* 107 */       this.marker += amount;
/*     */     }
/*     */     catch (IOException e) {
/* 110 */       debugOutputLn(16, "skipLength: " + e);
/* 111 */       throw new ParsingErrorException(e.getMessage());
/*     */     }
/*     */   }
/*     */
/*     */   public int getInt()
/*     */     throws ParsingErrorException
/*     */   {
/*     */     try
/*     */     {
/* 122 */       int x = 0;
/* 123 */       for (int i = 0; i < 4; i++) {
/* 124 */         int readResult = read();
/* 125 */         if (readResult == -1)
/* 126 */           throw new ParsingErrorException("Unexpected EOF");
/* 127 */         x = x << 8 | readResult;
/*     */       }
/* 129 */       return x;
/*     */     }
/*     */     catch (IOException e) {
/* 132 */       debugOutputLn(16, "getInt: " + e);
/* 133 */       throw new ParsingErrorException(e.getMessage());
/*     */     }
/*     */   }
/*     */
/*     */   public float getFloat()
/*     */     throws ParsingErrorException
/*     */   {
/* 143 */     return Float.intBitsToFloat(getInt());
/*     */   }
/*     */
/*     */   public String getFilename()
/*     */   {
/* 152 */     return this.theFilename;
/*     */   }
/*     */
/*     */   public String getString()
/*     */     throws ParsingErrorException
/*     */   {
/* 162 */     byte[] buf = new byte[512];
/*     */     try {
/* 165 */       int len = 0;
/*     */       byte b;
/*     */       do { b = (byte)read();
/* 168 */         buf[(len++)] = b; }
/* 169 */       while (b != 0);
/*     */
/* 171 */       if (len % 2 != 0) read();
/*     */     }
/*     */     catch (IOException e)
/*     */     {
/* 174 */       debugOutputLn(16, "getString: " + e);
/* 175 */       throw new ParsingErrorException(e.getMessage());
/*     */     }
/* 177 */     return new String(buf);
/*     */   }
/*     */
/*     */   public void getVerts(float[] ar, int num)
/*     */     throws ParsingErrorException
/*     */   {
/* 186 */     for (int i = 0; i < num; i++) {
/* 187 */       ar[(i * 3 + 0)] = getFloat();
/* 188 */       ar[(i * 3 + 1)] = getFloat();
/* 189 */       ar[(i * 3 + 2)] = (-getFloat());
/*     */     }
/*     */   }
/*     */
/*     */   public int getShortInt()
/*     */     throws ParsingErrorException
/*     */   {
/* 199 */     int i = 0;
/*     */     try {
/* 201 */       i = read();
/* 202 */       i = i << 8 | read();
/*     */
/* 204 */       if ((i & 0x8000) != 0) i |= -65536;
/*     */     }
/*     */     catch (IOException e)
/*     */     {
/* 207 */       debugOutputLn(16, "getShortInt: " + e);
/* 208 */       throw new ParsingErrorException(e.getMessage());
/*     */     }
/* 210 */     return i;
/*     */   }
/*     */
/*     */   public int getMarker()
/*     */   {
/* 220 */     return this.marker;
/*     */   }
/*     */
/*     */   public int read()
/*     */     throws IOException
/*     */   {
/* 226 */     this.marker += 1;
/* 227 */     return super.read();
/*     */   }
/*     */
/*     */   public int read(byte[] buffer, int offset, int count)
/*     */     throws IOException
/*     */   {
/* 233 */     int ret = super.read(buffer, offset, count);
/* 234 */     if (ret != -1) this.marker += ret;
/* 235 */     return ret;
/*     */   }
/*     */
/*     */   public LWOBFileReader(String filename)
/*     */     throws FileNotFoundException
/*     */   {
/* 244 */     super(new FileInputStream(filename));
/*     */
/* 247 */     this.debugPrinter = new DebugOutput(127);
/*     */
/* 249 */     this.marker = 0;
/*     */   }
/*     */
/*     */   public LWOBFileReader(URL url) throws IOException {
/* 253 */     super(url.openStream());
/*     */
/* 256 */     this.debugPrinter = new DebugOutput(127);
/*     */
/* 258 */     this.marker = 0;
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.loaders.lw3d.LWOBFileReader
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.loaders.lw3d.LWOBFileReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.